p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


Go Back   p2p.wrox.com Forums > XML > XSLT
I forgot my password Register Now
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.

Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox p2p Programmer to Programmer discussion community. This is a community of more than 40,000 computer programmers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining our free Wrox p2p community you can post your own programming questions and respond to other programmers’ questions. Registered users also don't have to see the ads that are displayed to guests. Registration is fast, simple and absolutely free so please, join today!
Join today and post to win prizes! Post more to increase your chances of being Wrox’s top poster of the month.

Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old April 16th, 2009, 10:40 AM
Friend of Wrox
Points: 1,343, Level: 14
Points: 1,343, Level: 14 Points: 1,343, Level: 14 Points: 1,343, Level: 14
Activity: 15%
Activity: 15% Activity: 15% Activity: 15%
 
Join Date: Jul 2006
Location: , , .
Posts: 366
Thanks: 8
Thanked 0 Times in 0 Posts
Send a message via Yahoo to bonekrusher
Default xsl:analyze-string - units of measure

Hi I am trying to extract units and measure from a string with the example provided here:

http://www.dpawson.co.uk/xsl/rev2/re...tml#d17781e331

My result is only non-matching-substring output - what am I doing wrong?

Code:
<xsl:template match="unitofmeasure">
        <xsl:analyze-string select="." regex="^(\d*(\.\d*)(in|cm|lbs|m))">
            <xsl:matching-substring>
                <measure>
                    <xsl:value-of select="regex-group(1)"/>
                </measure>
                <units>
                    <xsl:value-of select="regex-group(3)"/>
                </units>
            </xsl:matching-substring>
            <xsl:non-matching-substring>
                <value>
                    <xsl:value-of select="."/>
                </value>
            </xsl:non-matching-substring>
        </xsl:analyze-string>
    </xsl:template>
Input:

Code:
<root>
    <unitofmeasure type="lbs.2.kg">15.6lbs</unitofmeasure>
    <unitofmeasure type="inch.2.cm">14in</unitofmeasure>
    <unitofmeasure type="feet.2.m">14ft</unitofmeasure>
</root>
Current output:

Code:
<value>15.6lbs</value>
<value>14in</value>
<value >14ft</value>
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #2 (permalink)  
Old April 16th, 2009, 10:54 AM
mhkay's Avatar
Wrox Author
Points: 12,735, Level: 48
Points: 12,735, Level: 48 Points: 12,735, Level: 48 Points: 12,735, Level: 48
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 3,923
Thanks: 0
Thanked 82 Times in 80 Posts
Default

Your first example matches the regex, but regex-group(1) is the whole string: position the parentheses differently if you just want the number.

Your second and third examples don't match because the regex makes the decimal point mandatory, and the third one also doesn't match because "ft" is not in your list of units of measure accepted by the regex.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
The Following User Says Thank You to mhkay For This Useful Post:
bonekrusher (April 16th, 2009)
  #3 (permalink)  
Old April 16th, 2009, 12:12 PM
Friend of Wrox
Points: 1,343, Level: 14
Points: 1,343, Level: 14 Points: 1,343, Level: 14 Points: 1,343, Level: 14
Activity: 15%
Activity: 15% Activity: 15% Activity: 15%
 
Join Date: Jul 2006
Location: , , .
Posts: 366
Thanks: 8
Thanked 0 Times in 0 Posts
Send a message via Yahoo to bonekrusher
Default

Thank you very much!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Analyze-String and A Multiple-Match Example mphare XSLT 2 January 27th, 2009 05:21 PM
analyze-string and variables pcase XSLT 1 June 8th, 2007 05:22 PM
Available... Units in Stock j-parker BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 0 December 24th, 2006 07:27 PM
Active Directory Organizational Units r_ganesh76 ASP.NET 1.0 and 1.1 Professional 2 October 7th, 2004 01:58 AM
XSL Transform with xsl string NOT xsl file skin XSLT 0 June 16th, 2003 08:30 AM



All times are GMT -4. The time now is 02:54 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
© 2008 Wiley Publishing, Inc