我有一些 XML,例如,它看起来像这样:
<root>
<field1>test</field1>
<f2>t2</f2>
<f2>t3</f2>
</root>
我想用 XSLT 对其进行转换,但我想抑制输出中的第二个 f2 元素 - 如何在处理源中的第二个 f2 元素时检查我的模板内部是否已经存在输出中的 f2 元素?我的 XSLT 目前看起来像这样:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="no" omit-xml-declaration="yes" standalone="no" />
<xsl:template match="/">
<xsl:for-each select="./root">
<output>
<xsl:apply-templates />
</output>
</xsl:for-each>
</xsl:template>
<xsl:template match="*" >
<xsl:element name="{name(.)}">
<xsl:value-of select="." />
</xsl:element>
</xsl:template>
</xsl:stylesheet>
我需要对模板中的 xsl:element 进行某种检查,但我不确定如何查询输出文档以查看该元素是否已经存在。
编辑:忘记了 pre 标签,现在应该可以看到代码了!