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
Solved

XSL: obtain value after a currency text

Posted on 2013-12-11
8
224 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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
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

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
XML SQL 8 27
Changing alignment and creating border 6 39
Remove Space when printing webpage - Setup in Print.css 3 13
How to create a table with buttons 3 21
Many times as a report developer I've been asked to display normalized data such as three rows with values Jack, Joe, and Bob as a single comma-separated string such as 'Jack, Joe, Bob', and vice versa.  Here's how to do it. 
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
In this tutorial viewers will learn how to customize the background color and font color of highlighted text using the ::selection element in CSS Begin by defining the selected text as an element in CSS by typing "::selection": Style the ::selection…
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

856 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