Solved

XSL: obtain value after a currency text

Posted on 2013-12-11
8
219 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 500 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 500 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
 
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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Safari SVG Image Problem 1 39
get multiple images to align right 5 42
Remove greater than sign 3 42
WordPress Themes 10 34
The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
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…
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …

911 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now