Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

XSL: obtain value after a currency text

Posted on 2013-12-11
8
Medium Priority
?
229 Views
Last Modified: 2013-12-11
I have the following inputs
<Text>01 TEMP ANC FEE  USD  21.00   X23457</Text>
<Text>21 TEMP ANC FEE  CAD  10.50   X84564</Text>

I want to obtain the value right after the currency, regardless of what type of currency is being used.
I currently have

<xsl:variable name="test"
  select="
substring-before (substring-after(concat(normalize-space($Line[contains(Text, 'ANC FEE')][position() = $pos]), ' '), 'CAD '),' ')"/>
           
which returns 10.50 and as you can see only works for CAD.

How can i set this up, so that it'd return ANY value without it being currency specific?


And also, I'm curious to understand. what would be the difference between the two commands ( I see output as same)?

1. substring-before (substring-after(normalize-space($Line[contains(Text, 'ANC FEE')][position() = $pos]), 'CAD '),' ')"/>
2. substring-before (substring-after(concat(normalize-space($Line[contains(Text, 'ANC FEE')][position() = $pos]), ' '), 'CAD '),' ')"/>
0
Comment
Question by:badtz7229
  • 5
  • 2
8 Comments
 
LVL 15

Expert Comment

by:WalkaboutTigger
ID: 39712339
Have you looked at this string manipulation article?

http://www.xml.com/pub/a/2002/05/01/xslt-string.html

Essentially, if the length prior to the actual currency amount is consistent, you can use the substring function.

Also review http://www.keller.com/xslt/9/
0
 
LVL 60

Assisted Solution

by:Geert Bormans
Geert Bormans earned 2000 total points
ID: 39712343
The second one of the two options concats a ' ' at the end of the argument for substring.
As such it ensures that when you would have
<Text>21 TEMP ANC FEE  CAD  10.50</Text>
as input, it would still return the 10.50

The first one would not work in that occasion
0
 
LVL 60

Assisted Solution

by:Geert Bormans
Geert Bormans earned 2000 total points
ID: 39712348
About your task for making it work for both USD and CAD

<xsl:variable name="test"
  select="
substring-before (substring-after(translate(concat(normalize-space($Line[contains(Text, 'ANC FEE')][position() = $pos]), ' '), 'US', 'CA'), 'CAD '),' ')"/>

Since you are only interested in the numbers,
translate every U in a C and every D in an A and you would get away with it for this particular assignment
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 60

Expert Comment

by:Geert Bormans
ID: 39712356
I make this suggestion assuming this is the only information you have about the strings,
If size is a given or the numbers of components seperated by a space, we could use other techniques
0
 

Author Comment

by:badtz7229
ID: 39712390
I do know that there will always be 5 components before the amount. As in my examples above.
0
 
LVL 60

Accepted Solution

by:
Geert Bormans earned 2000 total points
ID: 39712518
Well, then this would be the better approach
(though likely not that readable)

   
<xsl:variable name="test"
        select="
        substring-before(substring-after(substring-after(substring-after(substring-after(substring-after(concat(normalize-space($Line[contains(Text, 'ANC FEE')][position() = $pos]), ' '), ' '), ' '), ' '), ' '), ' '),' ')
        "/> 

Open in new window

0
 

Author Closing Comment

by:badtz7229
ID: 39712589
thank you
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 39712698
welcome
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction If you're like most people, you have occasionally made a typographical error when you're entering information into an online form.  And to your consternation, the browser remembers the error, and offers to autocomplete your future entr…
Building a website can seem like a daunting task to the uninitiated but it really only requires knowledge of two basic languages: HTML and CSS.
In this Micro Tutorial users will learn how to embed custom fonts into websites using @font-face in CSS Select a font: Ensure the EULA allows you to use @font-face: Download the font: Get the browser-compatible files you need: Edit your CSS       - Name …
In this tutorial viewers will learn how add a full-size background image to a webpage using CSS3. Create a new HTML document with an internal stylesheet.: In CSS, define the html element to have a background image. Use a high resolution image.: In t…
Suggested Courses

927 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question