This conversion shows that xsl:analyze-string
not required to obtain the desired results - there is a simpler and more general solution. :
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output omit-xml-declaration="yes" indent="yes"/> <xsl:template match="*[matches(., '^Blah\s+(\d+)\s+Bloo\s+(\d+)\s+Blee')]"> <xsl:variable name="vTokens" select= "tokenize(replace(., '^Blah\s+(\d+)\s+Bloo\s+(\d+)\s+Blee', '$1 $2'), ' ')"/> <xsl:variable name="varX" select="$vTokens[1]"/> <xsl:variable name="varY" select="$vTokens[2]"/> <xsl:sequence select="$varX, $varY"/> </xsl:template> </xsl:stylesheet>
when applied to this XML document :
<t>Blah 123 Bloo 4567 Blee</t>
that produces the desired, correct result :
123 4567
Here we do not rely on the knowledge of RegEx (it can be supplied as a parameter) and the string - we just replace the string with the separator string of the RegEx groups, which we then designate, and each element in the resulting sequence with tokenize()
can be easily assigned the corresponding variable.
We do not need to search for the desired results, buried at a pace. tree - we just get them all in a sequence of results .
source share