0
我想修改一個XML文件,我在這個XML文件中有一些屬性,我想改變這個,即如果生產者是VW,那麼Iwant將國家改爲「德國」 票數是我的XML:用XSLT修改XML文件中的屬性
<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="example.xslt"?>
<Auto>
<lkw producer="VW" country="USA">
<name>Polo</name>
<price>$5955.2</price>
<color>red</color>
</lkw>
<lkw producer="Audi" country="germany">
<name>A8</name>
<price>$8955.2</price>
<color>black</color>
</lkw>
<lkw producer="BMW" country="USA">
<name>Polo</name>
<price>$6955.2</price>
<color>blue</color>
</lkw>
<lkw producer="VW" country="China">
<name>Pasat</name>
<price>$2955.2</price>
<color>red</color>
</lkw>
</Auto>
,這是我的XSLT:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl">
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="@producer[parent::VW]">
<xsl:attribute name="country">
<xsl:value-of select="'germany'"/>
</xsl:attribute>
</xsl:template>
</xsl:stylesheet>
但我看到在我的XML文件中沒有變化,能否請你告訴我,哪裏是我的XSLT錯誤?
屬性部分可以簡化爲的德國 xsl:attribute> –