我有一些XML,例如它看起来像这样:
<root>
<field1>test</field1>
<f2>t2</f2>
<f2>t3</f2>
</root>
Run Code Online (Sandbox Code Playgroud)
我想用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>
Run Code Online (Sandbox Code Playgroud)
我需要对我认为的模板中的xsl:元素进行某种检查,但我不确定如何查询输出文档以查看元素是否已经存在.
编辑:忘记预标签,代码现在应该可见!