Solved

XSL: use contains to filter variable further

Posted on 2013-11-07
7
291 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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

When applying CSS to your HTML, there are many different ways to select which element(s) the CSS applies to.  Some of these selectors are more commonly known and used than others - Here are the more common ones: #X - Matches an ID of X .X - Matche…
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 to define a gradient in CSS. Create a new HTML document with an internal stylesheet.: Create a div in CSS and name it Gradient. Define the background as "linear-gradient(to right, #ee3668, black)". Ensure you …
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…

929 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

10 Experts available now in Live!

Get 1:1 Help Now