Solved

XSL: obtain value after a currency text

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

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

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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

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, …
This is a how to build your own CSS3 slideshow and when I say CSS3 I mean just CSS with no javascript in sight! There a few examples online of how to do this but most just show you an example without any explanation, others make it more complicat…
In this tutorial viewers will learn how to style a decorative dropcap for the first letter in a paragraph using CSS. In CSS, create a new paragraph class by typing "p.fancy": Then, to style only the first letter of the first sentence, include the ps…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

770 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