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

November 27th, 2007, 09:18 AM
|
Friend of Wrox
|
|
Join Date: Jul 2006
Posts: 430
Thanks: 28
Thanked 5 Times in 5 Posts
|
|
Substring-before with Regex
Hi,
I am trying to use the substring-before function with a regex.
I want to grab any number at the beginning of the string the preceeds a non-numerical char.
Normally the <title> would be 22-10 or 6.1
I want to grab the number (e.g. 22, 6) before the first non-numerical char.
This is not working...
substring-before(//ACM:title, [^0-9])"
Thanks
|

November 27th, 2007, 09:26 AM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
|
|
substring-before doesn't accept regular expressions as far as I'm aware.
If you're using XSLT 2.0 you have 3 XPATH functions, tokenize(), matches() and replace() which accept regular expression patterns, along with the <xsl:analyze-string> XSLT declaration.
/- Sam Judson : Wrox Technical Editor -/
|

November 27th, 2007, 09:32 AM
|
Friend of Wrox
|
|
Join Date: Jul 2006
Posts: 430
Thanks: 28
Thanked 5 Times in 5 Posts
|
|
Thanks... This leads me to another question. I am using the substring-before() to group-by in a for-each-group.
How would I uses the <xsl:analyze-string> to group-by?
Thanks,
|

November 27th, 2007, 09:46 AM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
|
|
here's an example:
if <Numbers>1,4,6,7,10</Numbers>
then the following would split this and output each number:
<xsl:analyze-string select="Numbers" regex="[0-9]">
<xsl:matching-substring>
<Number><xsl:sequence select="."/></Number>
</xsl:matching-substring>
</xsl:analyze-string>
e.g.
<Number>1</Number><Number>2</Number>...
The inverse, where you split on the seperator:
<xsl:analyze-string select="Numbers" regex="[,]">
<xsl:non-matching-substring>
<Number><xsl:sequence select="."/></Number>
</xsl:non-matching-substring>
</xsl:analyze-string>
/- Sam Judson : Wrox Technical Editor -/
|

November 27th, 2007, 10:43 AM
|
 |
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
>I am trying to use the substring-before function with a regex.
Where did you find information that suggested you could do this? You can't.
>I want to grab the number (e.g. 22, 6) before the first non-numerical char.
You could use replace($input, '(^[0-9]*).*', '$1')
Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
|

November 27th, 2007, 10:44 AM
|
 |
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
>How would I uses the <xsl:analyze-string> to group-by?
The group-by expression can be any XPath expression. It can call a user-defined function, and the user-defined function can use <xsl:analyze-string>.
Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
|

November 27th, 2007, 01:16 PM
|
Friend of Wrox
|
|
Join Date: Jul 2006
Posts: 430
Thanks: 28
Thanked 5 Times in 5 Posts
|
|
Cool...Thank you!
|
|
 |