Solved

XSL: use contains to filter variable further

Posted on 2013-11-07
7
293 Views
Last Modified: 2013-11-07
i have the following variable within a function which finds 2 matching records

<xsl:variable name="test"      select="
 //Itin/ServInfo/Serv[@Code='ED' and @Type= 'RED'][Name/@Number =$Id]/Text"/>

 I want to filter even further by matching against a value within Text.
So my function would receive this param as $DocNum

<Text>AS KK1 06L18MAR/CHAIR/ACCPT/USD2000/100RC CCVIXXXXXXXXXXXX0001EXPXXXX 8312312270746</Text>

The $DocNum I would be filtering against is the last number included in this string. (8312312270746)

so that then variable "test" would return that entire text bc it found matching DocNum as well.
0
Comment
Question by:badtz7229
  • 4
  • 3
7 Comments
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 39630616
XSLT2 solution

<xsl:variable name="test"      select="
 //Itin/ServInfo/Serv[@Code='ED' and @Type= 'RED'][Name/@Number =$Id][ends-with(Text, $DocNum)]/Text"/>

XSLT1 Solution

<xsl:variable name="test"      select="
 //Itin/ServInfo/Serv[@Code='ED' and @Type= 'RED'][Name/@Number =$Id][substring(Text, string-length(Text) - string-length($DocNum) + 1 , string-length($DocNum))]/Text"/>
0
 

Author Comment

by:badtz7229
ID: 39630655
I used the XSLT21 solution and this returned two instances of <text>. It did not filter by DocNum
is there a way to use the "contains" function to filter?
0
 
LVL 60

Accepted Solution

by:
Geert Bormans earned 500 total points
ID: 39630707
is $DocNum equal to the number, or equal to the number in brackes?
In the latter case you need to filter the brackets first

I assumed it was important that the numbered string was at the end

Try
<xsl:variable name="test"      select="
 //Itin/ServInfo/Serv[@Code='ED' and @Type= 'RED'][Name/@Number =$Id][contains(Text, $DocNum)]/Text"/>

If Serv having the correct Text has two Text nodes, you will get them both
Use this instead then

<xsl:variable name="test"      select="
 //Itin/ServInfo/Serv[@Code='ED' and @Type= 'RED'][Name/@Number =$Id]/Text[contains(., $DocNum)]"/>
0
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.

 

Author Comment

by:badtz7229
ID: 39630711
sorry, no bracket. DocNum is equal to 8312312270746
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 39630717
then the above should work
0
 

Author Closing Comment

by:badtz7229
ID: 39630746
thanks both worked.
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 39630754
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

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
So you have coded your own WordPress plugin and now you want to allow users to upload images to a folder in the plugin folder rather than the default media location? Follow along and this article will show you how to do just that!
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 …
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

813 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

16 Experts available now in Live!

Get 1:1 Help Now