Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
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 Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old April 16th, 2009, 09:40 AM
Friend of Wrox
Join Date: Jul 2006
Posts: 430
Thanks: 28
Thanked 5 Times in 5 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:


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

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

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

<value >14ft</value>
Old April 16th, 2009, 09:54 AM
mhkay's Avatar
Wrox Author
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts

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
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
The Following User Says Thank You to mhkay For This Useful Post:
bonekrusher (April 16th, 2009)
Old April 16th, 2009, 11:12 AM
Friend of Wrox
Join Date: Jul 2006
Posts: 430
Thanks: 28
Thanked 5 Times in 5 Posts
Send a message via Yahoo to bonekrusher

Thank you very much!

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 04: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 12:58 AM
XSL Transform with xsl string NOT xsl file skin XSLT 0 June 16th, 2003 07:30 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.