• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 235
  • Last Modified:

XSL: Return value where it contains two text values

I have the following text
<Tick Number="TK 1234 SRET/H JGK4FXT 1108/16OCT - AS"/>

How can I retrieve the 1234 where @Number contains "TK" and "- AS"
I currently only am searching for "TK"        

<xsl:value-of select="substring-before(substring-after(normalize-space($Tkting[contains(@Number, 'TK')][position() = $pos]/@Number), ' '), ' ')"/>

I want to use this in a count variable as well. Such as
<xsl:variable name="count">
  <xsl:value-of select="count($Tkting[contains(@Number, 'TK')])"/>
  • 2
1 Solution
Geert BormansInformation ArchitectCommented:
just AND them

[contains(@Number, 'TK')][contains(@Number, '- AS')]
badtz7229Author Commented:
great. thanks .
Geert BormansInformation ArchitectCommented:

by the way, XSLT1.0 has a starts-with(), but not an ends-with()
XSLT2.0 has an ends-with

but you can emulate an ends-with() like this
[substring(@Number, string-length(@Number) - 3) = '- AS']
note that the '3' in there is the string-length of the end-matching string MINUS 1

or more crafty

<xsl:variable name="end-match" select="'- AS'"/>
and then the test would be
[substring(@Number, string-length(@Number) - string-length($end-match) + 1) = $end-match]
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now