|
|
 |
| 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.
|
 |

April 16th, 2009, 10:40 AM
|
|
Friend of Wrox
|
|
Join Date: Jul 2006
Location: , , .
Posts: 366
Thanks: 8
Thanked 0 Times in 0 Posts
|
|
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>
|

April 16th, 2009, 10:54 AM
|
 |
Wrox Author
Points: 12,735, Level: 48 |
|
|
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 3,923
Thanks: 0
Thanked 82 Times in 80 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
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
|
|
The Following User Says Thank You to mhkay For This Useful Post:
|
|

April 16th, 2009, 12:12 PM
|
|
Friend of Wrox
|
|
Join Date: Jul 2006
Location: , , .
Posts: 366
Thanks: 8
Thanked 0 Times in 0 Posts
|
|
Thank you very much!
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
 |