I have an XML, something like this:
<?xml version="1.0" encoding="UTF-8"?>
<earth>
<computer>
<parts>
<cpu>AMD;fast</cpu>
<video>GF</video>
<power>slow</power>
...others
</parts>
<owner>
<name>Frank</name>
<owner>
</computer>
<earth>
I want create xsl transform (xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"). My expected result only if cpu have sign ';' - power should be change to value after ';', if there will not be ';' result should no change
<earth>
<computer>
<parts>
<cpu>AMD</cpu>
<video>GF</video>
<power>fast</power>
...others
</parts>
<owner>
<name>Frank</name>
<owner>
</computer>
<earth>
Try to do something like this but no luck:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fn="http://www.w3.org/2005/xpath-functions"
exclude-result-prefixes="fn">
<xsl:output encoding="utf-8" method="xml" indent="yes" />
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()" />
</xsl:copy>
</xsl:template>
<xsl:template match="parts">
<xsl:choose>
<!-- try test if node name equals 'power' if equals them try make logic
here, this dont work-->
<xsl:when test="name() = 'power'">
<xsl:variable name="text" select="./cpu" />
<xsl:variable name="sep" select="';'" />
<xsl:variable name="powerTable" select="tokenize($text, $sep)" />
<xsl:value-of select="$powerTable[1]" />
</xsl:when>
<!--if not 'power' copy node -->
<xsl:otherwise>
<xsl:copy>
<xsl:apply-templates select="@* | node()" />
</xsl:copy>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>