[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: how to ask analyze-string for only one match?

Subject: RE: how to ask analyze-string for only one match?
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Mon, 23 Jan 2006 21:01:07 -0000
regex only one
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/

> -----Original Message-----
> From: Roger I Martin PhD [mailto:hypernexdev@xxxxxxxxxxxxxxx] 
> Sent: 23 January 2006 20:52
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject:  how to ask analyze-string for only one match?
> 
> I'm transforming svg.  In particular path data noted by the d 
> attribute.
> -----
>   <path d="M 100 100 L 300 100 L 200 300 z"
>         fill="red" stroke="blue" stroke-width="3" />
> ----
> In this example there are 3 matches 100 100, 300 100 and 200 
> 300.  The 
> following gives me all 3 but I want it to stop after the 
> first match.  
> Added a {1} for group 1 but that doesn't stop the rematch 
> from occuring.
> -----
>     <xsl:template name="apply-absolute-point">
>     <xsl:param name="d-path" select="''"/>
>             <xsl:analyze-string select="$d-path" 
> 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>
>     </xsl:template>
> ----

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.