Reputation: 83
The problem is as follows: My XML has element with content "x/y". This indicates the running number of "part" coming in. E.g. in first XML this element will have value 1/5, in second 2/5 and in last one 5/5. You get the point. The element itself looks like
<part>x/y</part>
where x might be something between 1 and y, and y can be any number
I would need to find answer to two cases:
How to solve this using XSL (version 1.0) ?
Upvotes: 1
Views: 179
Reputation: 111726
Use substring-before()
:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text"/>
<xsl:template match="part">
<xsl:variable name="x" select="substring-before(., '/')"/>
<xsl:variable name="y" select="substring-after(., '/')"/>
<xsl:choose>
<xsl:when test="$x = 1">Add</xsl:when>
<xsl:when test="$x = $y">Complete</xsl:when>
<xsl:otherwise>
<xsl:value-of select="concat('Unexpected values for x,y: ', $x, ',', $y)"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
Upvotes: 1