我有以下 XML 代码。
您会注意到标签描述重复,但具有不同的属性。
我正在使用 XSLT 尝试删除具有 enabled 属性的 Description 标记。
<Batch>
- <Promotion>
<LastUpdated>2008-01-22T11:58:05+00:00</LastUpdated>
<MajorVersion>1</MajorVersion>
<MinorVersion>29</MinorVersion>
<PromotionID>000873</PromotionID>
<Description enabled="1">*P* Free Mistletoe</Description>
<Description country="GB" language="en" variant="">WANTED LINE 1</Description>
</Promotion>
<Promotion>
<LastUpdated>2008-01-22T11:58:05+00:00</LastUpdated>
<MajorVersion>1</MajorVersion>
<MinorVersion>29</MinorVersion>
<PromotionID>000874</PromotionID>
<Description enabled="1">*P* Free Mistletoe</Description>
<Description country="GB" language="en" variant="">WANTED LINE 2</Description>
</Promotion>
</batch>
这就是我想要达到的目标,还有其他标签,它是根据我试图解决的属性删除一行。
- <promotions>
- <promotion>
<promotionID>000873</promotionID>
<description country="GB" language="en" variant="">WANTED LINE 1</description>
</promotion>
- <promotion>
<promotionID>000874</promotionID>
<description country="GB" language="en" variant="">WANTED LINE 2</description>
</promotion>
</promotions>
我正在使用的 XSLT 代码是
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="//promotion/Description[@country='GB']"/>
<xsl:template match="/">
<promotions>
<xsl:for-each select="Batch/Promotion">
<promotion>
<promotion_id><xsl:value-of select="PromotionID"/></promotion_id>
<description><xsl:value-of select="Description"/></description>
</promotion>
</xsl:for-each>
</promotions>
</xsl:template>
</xsl:stylesheet>
如果有人能指出我正确的方向,我将不胜感激。
保罗