Solved

XSL: use contains to filter variable further

Posted on 2013-11-07
7
286 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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 

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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

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, …
Why do we like using grid based layouts in website design? Let's look at the live examples of websites and compare them to grid based WordPress themes.
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…
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

707 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

18 Experts available now in Live!

Get 1:1 Help Now