At times a simple task in xslt looks like a puzzle. Today we have this one.
For a string and a regular expression find a position and a length of the matched substring.
The problem looks so simple that you do not immediaty realize that you are going to spend ten minutes trying to solve it in the best way.
Try it yourself before proceeding:
<xsl:variable name="match" as="xs:integer*"> <xsl:analyze-string select="$line" regex="my-reg-ex"> <xsl:matching-substring> <xsl:sequence select="1, string-length(.)"/> </xsl:matching-substring> <xsl:non-matching-substring> <xsl:sequence select="0, string-length(.)"/> </xsl:non-matching-substring> </xsl:analyze-string> </xsl:variable> <xsl:choose> <xsl:when test="$match[1]"> <xsl:sequence select="1, $match[2]"/> </xsl:when> <xsl:when test="$match[3]"> <xsl:sequence select="$match[2], $match[4]"/> </xsl:when> </xsl:choose>
Remember Me
a@href@title, b, blockquote@cite, em, i, strike, strong, sub, super, u