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 June 8th, 2007, 02:01 PM
Authorized User
 
Join Date: Jun 2007
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Default analyze-string and variables

I am wanting to capture each portion (denoted with parenthesis) of the following string, where each of the portions are optional. Possible strings could be:

4Y6M12D
4Y12D
6M

Where

$year = '4Y'
$month = '6M'
$day = '12D'

I thought I could use:
<xsl:analyze-string select="'4Y6M12D'" regex="(\d{1,2}Y)(\d{1,2}M)(\d{1,2}D)">

<xsl:matching-substring>
<xsl:variable name="year" select="regex-group(1)"/>
<xsl:variable name="month" select="regex-group(2)"/>
<xsl:variable name="day" select="regex-group(3)"/>
</xsl:matching-substring>

</xsl:analyze-string>

Is there a better way to capture these variables. I know I can use matches() to return a boolean, but is there an equivalent that will return just that portion of the string that matches the regex.

somefunction('4Y12D','(\d{1,2}Y)') returns 4Y

 
Old June 8th, 2007, 04:22 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

The regex attribute of xsl:analyze-string is an attribute value template, so curly braces need to be doubled. Alternatively put the regex in a variable:

<xsl:variable name="regex">(\d{1,2}Y)(\d{1,2}M)(\d{1,2}D)</xsl:variable>
<xsl:analyze-string select="'4Y6M12D'" regex="{$regex}">

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference





Similar Threads
Thread Thread Starter Forum Replies Last Post
Analyze if ActiveCell is part of specified Range babers09 Excel VBA 1 June 14th, 2007 09:12 PM
Analyze of a Blob yanis97 Java Databases 0 September 16th, 2006 12:04 PM
Analyze of a BLOB yanis97 J2EE 0 September 8th, 2006 05:37 AM
Oracle's Analyze Table equivalent ? smitha SQL Server 2000 1 October 27th, 2004 04:04 PM
Oracle's Analyze Table equivalent ? smitha SQL Server 2000 1 October 11th, 2004 08:24 AM





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