复制 XML 文件内容并将 XSLT 处理日志输出写入单独的文件
Copy XML file content and write XSLT processing log output in separate file
我有一个 XSL 转换,我在其中更正了属性的拼写。这很好用。但是当我跳过更正时(因为更正的属性已经存在)然后我想把它记录在一个单独的文件中。
这 2 个任务分开工作,但是当我尝试将它们放在一起时,只写入了日志文件,但我想要两个输出 - 结果 XML 和日志文件。如何解决?
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:variable name="processingFileName" select="base-uri()" />
<!------- This corrects the spelling in the XML ---------->
<xsl:template match="node()|@*" >
<xsl:copy>
<xsl:apply-templates select="node()|@*" />
</xsl:copy>
</xsl:template>
<xsl:template match="Attribute[@Name = 'Clor']" >
<xsl:if test="not(../Attribute[@Name = 'Color'])">
<Attribute Name="Color" Value="{@Value}" />
</xsl:if>
</xsl:template>
<!------- This logs skipped parts in a log file ---------->
<xsl:template match="/" >
<xsl:result-document method="text" href="{$processingFileName}.log">
<xsl:apply-templates mode="logging" select="/export/parts/part/Attribute" />
</xsl:result-document>
</xsl:template>
<xsl:template match="Attribute[@Name = 'Clor']" mode="logging">
<xsl:if test="(../Attribute[@Name = 'Color'])">
<xsl:value-of select="../@PartNo" />
<xsl:text> </xsl:text>
</xsl:if>
</xsl:template>
通过更改
确保您的文档后代也使用默认模式
<xsl:template match="/" >
<xsl:result-document method="text" href="{$processingFileName}.log">
<xsl:apply-templates mode="logging" select="/export/parts/part/Attribute" />
</xsl:result-document>
</xsl:template>
至
<xsl:template match="/" >
<xsl:apply-templates/>
<xsl:result-document method="text" href="{$processingFileName}.log">
<xsl:apply-templates mode="logging" select="/export/parts/part/Attribute" />
</xsl:result-document>
</xsl:template>
我有一个 XSL 转换,我在其中更正了属性的拼写。这很好用。但是当我跳过更正时(因为更正的属性已经存在)然后我想把它记录在一个单独的文件中。
这 2 个任务分开工作,但是当我尝试将它们放在一起时,只写入了日志文件,但我想要两个输出 - 结果 XML 和日志文件。如何解决?
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:variable name="processingFileName" select="base-uri()" />
<!------- This corrects the spelling in the XML ---------->
<xsl:template match="node()|@*" >
<xsl:copy>
<xsl:apply-templates select="node()|@*" />
</xsl:copy>
</xsl:template>
<xsl:template match="Attribute[@Name = 'Clor']" >
<xsl:if test="not(../Attribute[@Name = 'Color'])">
<Attribute Name="Color" Value="{@Value}" />
</xsl:if>
</xsl:template>
<!------- This logs skipped parts in a log file ---------->
<xsl:template match="/" >
<xsl:result-document method="text" href="{$processingFileName}.log">
<xsl:apply-templates mode="logging" select="/export/parts/part/Attribute" />
</xsl:result-document>
</xsl:template>
<xsl:template match="Attribute[@Name = 'Clor']" mode="logging">
<xsl:if test="(../Attribute[@Name = 'Color'])">
<xsl:value-of select="../@PartNo" />
<xsl:text> </xsl:text>
</xsl:if>
</xsl:template>
通过更改
确保您的文档后代也使用默认模式<xsl:template match="/" >
<xsl:result-document method="text" href="{$processingFileName}.log">
<xsl:apply-templates mode="logging" select="/export/parts/part/Attribute" />
</xsl:result-document>
</xsl:template>
至
<xsl:template match="/" >
<xsl:apply-templates/>
<xsl:result-document method="text" href="{$processingFileName}.log">
<xsl:apply-templates mode="logging" select="/export/parts/part/Attribute" />
</xsl:result-document>
</xsl:template>