The XML File:
<XML>
<Item ID = "test1"></Item>
<Item ID = "test2"></Item>
</XML>
Result:
<XML>
<Item ID = "TEST01"></Item>
<Item ID = "TEST02"></Item>
</XML>
In my XSLT 2.0 file I want to acess the NewID of the variable if the currentID is equal to the OldID in order to change the attributes value with the predefined NewID.
<xsl:variable name="Items">
<Item OldID="test1" NewID = "TEST01"></Item>
<Item OldID="test2" NewID = "TEST02"></Item>
</xsl:variable>
<xsl:template match="XML">
<xsl:copy>
<xsl:apply-templates />
</xsl:copy>
</xsl:template>
<xsl:template match="Item">
<xsl:copy-of select="@*[name()!='ID']" />
<xsl:attribute name="ID">
<xsl:value-of select="$Items/Item[@OldID = @ID]/@NewID"/>
</xsl:attribute>
</xsl:copy>
</xsl:template>
Try:
<xsl:value-of select="$Items/Item[@OldID = current()/@ID]/@NewID"/>
--
PS Suggested reading: http://www.w3.org/TR/xslt20/#key
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.