Solved

XSL: use contains to filter variable further

Posted on 2013-11-07
7
299 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
[X]
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
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
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

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

How our DevOps Teams Maximize Uptime

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

Question has a verified solution.

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

This is a how to build your own CSS3 slideshow and when I say CSS3 I mean just CSS with no javascript in sight! There a few examples online of how to do this but most just show you an example without any explanation, others make it more complicat…
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.
In this Micro Tutorial viewers will learn how to create navigation buttons that change on rollover, using CSS (Continuation of the CSS Image Sprite tutorial) Create a parent ID for all the list items       - Specify position: absolute and display: block…
In this tutorial viewers will learn how to position overlapping items using z-index in CSS. They will also learn the restrictions on the z-index property.  Create a new HTML document with an internal stylesheet.: Create a div in CSS and name it Red.…

705 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