If statement xslt替换属性';s值,但也会清空其他属性
我正在使用XSLT1.0,下面是我的xml文件。如果code=“Hello”,我想将属性代码的值更新为“Chao”。我写了一个小脚本,它将code=“Hello”更新为code=“Chao”;但是,它也会清空其他代码属性。你能帮忙吗? **XMLIf statement xslt替换属性';s值,但也会清空其他属性,if-statement,xslt,If Statement,Xslt,我正在使用XSLT1.0,下面是我的xml文件。如果code=“Hello”,我想将属性代码的值更新为“Chao”。我写了一个小脚本,它将code=“Hello”更新为code=“Chao”;但是,它也会清空其他代码属性。你能帮忙吗? **XML <Items> <Item itemIdentifier="07068283" code="Hello" /> <Item itemIdentifier="07059182" code="Hello" /> <
<Items>
<Item itemIdentifier="07068283" code="Hello" />
<Item itemIdentifier="07059182" code="Hello" />
<Item itemIdentifier="07063805" code="Bye" />
<Item itemIdentifier="07064878" code="Bye" />
</Items>
代码**
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:strip-space elements="*"/>
<!-- identity transform -->
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="Item/@code">
<xsl:attribute name="code">
<xsl:if test=". = 'Hello'">Chao</xsl:if>
</xsl:attribute>
</xsl:template>
</xsl:stylesheet>
赵
结果
<Items>
<Item itemIdentifier="07068283" code="Chao"/>
<Item itemIdentifier="07059182" code="Chao"/>
<Item itemIdentifier="07063805" code=""/>
<Item itemIdentifier="07064878" code=""/>
</Items>
试试:
赵
user12448901迈克尔有一个很好的答案。hor257k
<xsl:template match="Item/@code[.='Hello']">
<xsl:attribute name="code">Chao</xsl:attribute>
</xsl:template>