Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
If statement xslt替换属性';s值,但也会清空其他属性_If Statement_Xslt - Fatal编程技术网

If statement xslt替换属性';s值,但也会清空其他属性

If 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" /> <

我正在使用XSLT1.0,下面是我的xml文件。如果code=“Hello”,我想将属性代码的值更新为“Chao”。我写了一个小脚本,它将code=“Hello”更新为code=“Chao”;但是,它也会清空其他代码属性。你能帮忙吗? **XML

<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>