XSL: use contains to filter variable further

Posted on 2013-11-07
Medium Priority
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.
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
  • 4
  • 3
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"/>

Author Comment

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?
LVL 60

Accepted Solution

Geert Bormans earned 2000 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

<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)]"/>
Technology Partners: 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!


Author Comment

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

Expert Comment

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

Author Closing Comment

ID: 39630746
thanks both worked.
LVL 60

Expert Comment

by:Geert Bormans
ID: 39630754

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Introduction A frequently asked question goes something like this:  "I am running a long process in the background and I want to alert my client when the process finishes.  How can I send a message to the browser?"  Unfortunately, the short answer…
When writing CSS, there are a few simple rules that will make your life easier.    1. Using ‘* {box-sizing:border-box;}’. Using this will wrap all your elements in a nice little compact box-model that will give you the width you want, like so... …
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…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).
Suggested Courses

649 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