我需要能夠去除取決於包含段落的子元素<version>
中的屬性指定的父節點(及其子女)的屬性中刪除父節點。因此,在下面的例子中,我需要XSLT找到<version version="ABCD">
的實例,並從父<para0>
元素中刪除所有內容。換句話說,我試圖完成條件文本過濾。 i的元素需要匹配(和刪除)將永遠是<applic>
父,但可能不總是<para0>
作爲例子,所以我需要指定某種方式,它需要匹配「應用程」元素的父元素,而不是明確指定para0。C#XSLT基於childnode
應該從例子中清晰。我需要刪除版本屬性爲ABCD的所有para0數據。
所以這是一些示例XML
<root>
<para0>
<applic>
<model>
<version version="ABCD"></version>
</model>
</applic>
<subpara1><title>First Title</title>
<para>Some text relating to ABCD configuration</para>
</subpara1>
<subpara1><title>Second Title</title>
<para>Some other text and stuff relating to ABCD configuration</para>
</subpara1>
</para0>
<para0>
<applic>
<model>
<version version="TRAINING"></version>
</model>
</applic>
<subpara1><title>First Title</title>
<para>Some text relating to TRAINING configuration</para>
</subpara1>
<subpara1><title>Second Title</title>
<para>Some other text and stuff relating to TRAINING configuration</para>
</subpara1>
</para0>
</root>
這裏是XSLT我有這麼遠,但我需要它,一旦匹配到ABCD,基本上選擇並刪除父「應用程」和所有的子節點。
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method = "xml" indent="yes"/>
<xsl:strip-space elements = "*" />
<xsl:template match = "@*|node()" >
<xsl:copy>
<xsl:apply-templates select = "@*|node()" />
</xsl:copy>
</xsl:template>
<xsl:template match = "//applic/model[@*]/version[@version='ABCD']" />
</xsl:stylesheet>
的可能的複製[如何使用XPath的 「不」?](http://stackoverflow.com/questions/1550981/how-to -use-不在位的XPath) –