mr wares
mr wares

Reputation: 103

Access matched pattern within XSL tokenize

Suppose I have the following variable

<xsl:variable name="randomString" select="'COLUMN1 == 400 or COLUMN1 == 5 and COLUMN2 != 3'" />

Is there any convenient way to access the matched pattern within the tokenize() function e.g. using this

<xsl:for-each select="tokenize($randomString, 'and|or')">
  <xsl:value-of select="concat('not(', current(), ')')" />
  <!-- How do I access the matched pattern? -->
</xsl:for-each>

Or do I have to use a custom template like the one I have found here http://docbook.sourceforge.net/release/xsl/1.77.0/doc/lib/str.tokenize.keep.delimiters.html

Upvotes: 3

Views: 79

Answers (1)

LarsH
LarsH

Reputation: 27996

No, there is no way to retrieve the matched separator. "The separators themselves are not returned." (http://www.w3.org/TR/xpath-functions/#func-tokenize)

A workaround could be, tokenizing with or as a separator in an outer loop, then tokenizing with and as a separator in an inner loop. Then you would always know which separators you were dealing with, based on where in the loops you are.

Another approach would be to use analyze-string(). See this answer.

Upvotes: 1

Related Questions