I want to to select all the nodes for a given id but that could end in an additional number. How can I do that?
Example:
<group id="list">
<group id="list1">
<group id="list2">
<group id="map">
<group id="map1">
The declaration Im having now:
<xsl:variable name="rule">
<data>
<node>list</node>
<node>map</node>
</data>
</xsl:variable>
<xsl:template match="/">
<xsl:apply-templates select=".//group[ @id = exslt:node-set($rule)/data/node]"/>
</xsl:template>
and it only allows my to work on the nodes specified in the “rule” list. [XSLT v1.0]
Please advise.
I. XSLT 1.0 solution:
This transformation:
when applied on this XML document:
processes (in this example copies) exactly the matching nodes:
Explanation:
Use of the standard XPath functions
starts-with(),substring-after()andfloor().An easy test if a string is castable to an integer is:
floor($s) = $sII. XSLT 2.0 solution:
Explanation: This solution is quite similar to the XSLT 1.0 solution with the following major differences:
In XSLT 2.0 it is allowed to have variable/parameter references in the match pattern. Using this we avoid the
<xsl:if>inside the template body.We define the parameter to contain a sequence of the desired strings.
We use the standard XPath 2.0 operator
castable as.