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

March 5th, 2007, 09:38 AM
|
Friend of Wrox
|
|
Join Date: Jul 2006
Posts: 430
Thanks: 28
Thanked 5 Times in 5 Posts
|
|
Replace decimal point with another value
Hi,
Is it possible to replace a decimal point with another value?
Input
<Element>1.2.3</Element>
Code:
<xsl:value-of select="replace(Element,'.', '_')"/>
Returns "___"
Desired HTML results
"1_2_3"
Thanks for the help.
|

March 5th, 2007, 09:57 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
|
|
Sorry but I don't believe you :)
What XSLT processor gives this result? Are you certain that Element contains what you think it does?
--
Joe ( Microsoft MVP - XML)
|

March 5th, 2007, 10:06 AM
|
Friend of Wrox
|
|
Join Date: Jul 2006
Posts: 430
Thanks: 28
Thanked 5 Times in 5 Posts
|
|
Hmm interesting. I am using XMLspy..
I verified the element does contian decimals....
|

March 5th, 2007, 10:27 AM
|
Friend of Wrox
|
|
Join Date: Jul 2006
Posts: 430
Thanks: 28
Thanked 5 Times in 5 Posts
|
|
I also ran it in SAXON 8.8 and get the same results...any thoughts?
|

March 5th, 2007, 10:50 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
|
|
Post the XML and the XSLT, I will try it on my system.
--
Joe ( Microsoft MVP - XML)
|

March 5th, 2007, 10:52 AM
|
 |
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
Use the translate function.
replace() uses regular expressions, in which "." matches any character. If you want to use replace, use "\." to match a period.
Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
|

March 5th, 2007, 10:53 AM
|
Friend of Wrox
|
|
Join Date: Jul 2006
Posts: 430
Thanks: 28
Thanked 5 Times in 5 Posts
|
|
Ok..I got it.
I used:
<xsl:value-of select="replace(Element,'\W+', '_')"/>
Thanks Michael,
"\." does the trick also.
Thanks a bunch
|

March 5th, 2007, 11:02 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
|
|
Ok sorry I completely misread the post, I thought you were using the translate function [:)}. A trip to the opticians is in order.
Code:
translate(Element, '.', '_')
--
Joe ( Microsoft MVP - XML)
|

March 5th, 2007, 12:22 PM
|
Friend of Wrox
|
|
Join Date: Jul 2006
Posts: 430
Thanks: 28
Thanked 5 Times in 5 Posts
|
|
No worries.. everyday I learn!
|
|
 |