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

Re: Using xsl:analyze-string and regex to parse long

Subject: Re: Using xsl:analyze-string and regex to parse long lines with white-space
From: Abel Braaksma <abel.online@xxxxxxxxx>
Date: Tue, 19 Jun 2007 20:48:15 +0200
Re:  Using xsl:analyze-string and regex to parse long
Rob Newman wrote:
Hi All,


I am trying to parse the contents of <pfstring> to get the 5th column ("TA_D03A" in the example), the 10th ("regular internet") and the 11th ("hosted") for each line and push it to "output.xml" thus:


<snip />

Each entry in input.xml/pfarr/pfstring is on a new line. I am trying to use the regex functions and have the following, but it does not seem to be working:



<xsl:analyze-string select="$elValue" regex="\s*(.*)\s+(.*)\s+(.*)\s+(.*)\s+(.*)\s+(.*)\s+(.*)\s+(.*)\s+(.*)\s+(.*)\s+(.*)\s+\n">



You seem to be trying to capture it all at once. But you are not taking into consideration the basic greediness of any regular expression (this is explained, for instance, on www.regular-expressions.info). Instead of trying to match it all at once, there's (in your case) a much simpler way to match this:

<xsl:for-each select="tokenize($elValue, '\n')">
   <xsl:for-each select="tokenize($elValue, '\s+')">
        do your stuff
   </xsl:for-each>
</xsl:for-each>

You may want to put the second for-each in a variable, which makes for easy reference by index:

<xsl:for-each select="tokenize($elValue, '\n')">
   <xsl:variable select="tokenize($elValue, '\s+')" name="values" />
   do your stuff with $values
</xsl:for-each>

HTH,
Cheers,
-- Abel

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.