Re: [xsl] how to ask analyze-string for only one match?

Subject: Re: [xsl] how to ask analyze-string for only one match?
From: Roger I Martin PhD <hypernexdev@xxxxxxxxxxxxxxx>
Date: Mon, 23 Jan 2006 17:27:09 -0500
Thanks Michael,
That will do nicely and actually opens up a better way to do the whole task at hand. The path data is even more complex for example
<path style="fill-rule:evenodd;clip-rule:evenodd;stroke:none;" d="M145.876,414.692c3-1.9,5.6-0.5,7.8,4.3c0.1,1.8,0.2,2.7,0.5,3.6c0.3,0.9,0,1.9-0.9,2.8c-0.8,1-1.8,1-2.9,0s-1.8-0.899-2.3,0.4s0.4,2.6,2.8,3.9c1.1,0.5,1.4,1.199,1.7,2.6c0.2,1.3,0,1.9-0.6,1.7s-1.5-0.101-2.6,0.2c-1.1,0.399-1.6,0.1-1.5-1c0-1.101,0.1-1.9,0.1-2.301c0.5-2.1-0.4-2.6-2-1.699c-1.6,0.899-3,0.699-4.1-0.4c-2.1-2.5-1.7-3.6,0.3-3.3s1.5-0.2-1.3-1.601c0.1-4.1-0.9-6-3.8-6c1.5-2.5,2.6-2.899,4.1-1.6c1.5,1.4,2.4,0.9,2.7-1.4l2-0.199z"/>
with potential commands M, m, L ,l, H, h, V, v, C, c, S, s, Q, q, T, t, A, a, Z, and z commands. What you showed me with some rearrangement of my regex's will march thru much more robustly and rapidly!


-Roger

Michael Kay wrote:

One way to do this is to write your analyze-string to process all the
matches, put the result in a sequence-valued variable, and select the first
item in that resulting sequence.


<xsl:variable name="s" as="xs:string*">
<xsl:analyze-string select="$d-path" regex="((\-?(\.|\d)+)(,| )+(\-?(\.|\d)+)){{1}}">
<xsl:matching-substring>
<xsl:sequence select="."/>
</xsl:matching-substring>
</xsl:analyze-string>
</xsl:variable>
<xsl:analyze-string select="$s[1]">
regex="((\-?(\.|\d)+)(,| )+(\-?(\.|\d)+)){{1}}">
<xsl:matching-substring>
currentX=<xsl:value-of select="regex-group(2)"/>f;
currentY=<xsl:value-of select="regex-group(5)"/>f; </xsl:matching-substring>
</xsl:analyze-string>


Michael Kay
http://www.saxonica.com/

Current Thread