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 October 14th, 2011, 03:44 AM
Registered User
 
Join Date: Aug 2011
Posts: 9
Thanks: 2
Thanked 0 Times in 0 Posts
Default Wildcards in XSLT

Hello, i have a Problem in my Scrips, i use XML and XSLT to fill an Indesign Document.

My mainquestion is:
If i have a Price with 3 Numbers behind the the point, how can i get the last number?

Is there something like a Wildcard?

My xml is looking like this:
Code:
<price>4.975</price>
and i want to change the last number if the number is 5.
Something like
Code:
if price *.**5 Then *.**6
is that possible?

Thank you for help
 
Old October 14th, 2011, 04:30 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

XSLT 2.0 contains the replace() and matches() function which use regular expressions (which contains its own wildcard characters).

Otherwise you would need to either treat the number as a string and use sub-string functions, or treat is as a number and use rounding or modulus calculations.
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?
 
Old October 14th, 2011, 04:56 AM
Registered User
 
Join Date: Aug 2011
Posts: 9
Thanks: 2
Thanked 0 Times in 0 Posts
Default

Thank you for the fast answer, that sounds good. But im pretty new with xslt, can you gibe me a little more help, im a little bit in a hurry.
Sorry for asking, i know, normaly a forum is only to show me the right direction.

How has the replace code to look like?

Thank you for help
 
Old October 14th, 2011, 08:24 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

Well in XSLT 2.0 it would be something like this:

Code:
<xsl:choose>
<xsl:when test="matches(price, '\d+\.\d\d5')">
  <xsl:value-of select="replace(price, '(\d+\.\d\d)5', '$16')"/>
</xsl:when>
<xsl:otherwise><xsl:value-of select="price"/></xsl:otherwise>
</xsl:choose>
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?
The Following User Says Thank You to samjudson For This Useful Post:
Beckers (October 18th, 2011)
 
Old October 18th, 2011, 03:43 AM
Registered User
 
Join Date: Aug 2011
Posts: 9
Thanks: 2
Thanked 0 Times in 0 Posts
Default

Hello samjudson, thanks a lot for you help, i tried it and its really works for my Transformer, but not for InDesign, i dont know what happen, i work with XSLT 2.0 and XML 1.0 but InDesign wont work with that code.

Now im Trying with Else and Otherwise but that is not working too and it looks just bad.

So maybe you can gibe me an other example? maybe for XSLT 1.0?
that would be realy nice
 
Old October 18th, 2011, 03:55 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

Does InDesign have its own XSLT processor? Well it mustn't be XSLT 2.0 then.

Something like this might work:

Code:
<xsl:when test="substring(price, string-length(price)-1,1)='5'">
This would simply check the last digit for a 5. If you also had numbers where their might only be 2 or 1 decimal place and these might be 5 as well you would have to put extra checks in to check that "string-length(substring-after(price,'.'))=3" was also true perhaps?

For all the string functions in XSLT 1.0 look here: http://www.w3.org/TR/xpath/#function-string
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?
The Following User Says Thank You to samjudson For This Useful Post:
Beckers (October 18th, 2011)
 
Old October 18th, 2011, 04:27 AM
Registered User
 
Join Date: Aug 2011
Posts: 9
Thanks: 2
Thanked 0 Times in 0 Posts
Default

Thank you so much for the fast answer.
Now it is working!

i had a second problem with the code and now i could solve both problems with your help, thanks!





Similar Threads
Thread Thread Starter Forum Replies Last Post
How to disable the wildcards(% and _) kasipandian Oracle 1 February 4th, 2008 12:32 AM
ObjectDataSource and Wildcards pipelineconsulting ASP.NET 2.0 Professional 1 October 19th, 2006 09:08 PM
XSLT Wildcards? kwilliams XSLT 2 September 28th, 2005 10:54 AM
Datetime, wildcards etc SoC Classic ASP Basics 6 July 19th, 2005 08:53 PM
Using wildcards in subquery hman SQL Language 2 April 11th, 2005 06:18 AM





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