XSL: obtain value after a currency text

Posted on 2013-12-11
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"
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 '),' ')"/>
Question by:badtz7229
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 2
LVL 15

Expert Comment

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

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

Also review
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
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"
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
More Than Just A Video Library

Train for your certification. Learn the latest DevOps tools. Grow your skillset to do better work.

At Linux Academy, we release new training modules every week so you'll always be up to date on the latest tech.

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

Author Comment

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

Accepted Solution

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


Author Closing Comment

ID: 39712589
thank you
LVL 60

Expert Comment

by:Geert Bormans
ID: 39712698

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
In this tutorial viewers will learn how add a scalable full-width header using CSS3. Create a new HTML document with an internal stylesheet. Set a tiled background.:  Create a new div and name it Header. Position it with position:absolute at the top…
In this tutorial viewers will learn how to embed custom externally-hosted Google Fonts using the Google Font API in CSS Go to the Google Fonts website at Browse or search based on font properties or name to find a suitable font for…

728 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