Reputation: 27
How to use the choose condition in XSLT when the below requirement is needed
<xsl:choose>
<xsl:when test="contains(@name,'top %d holdings' ) ">
<!--code-->
</xsl:when>
</xsl:choose>
It should select all the data containing....
Upvotes: 1
Views: 261
Reputation: 66723
You can use substring-before() and substring-after() to get the text between top
and holdings
, and then use the translate() function to remove numbers and the *
character, and then verify that the result is an empty string.
<xsl:choose>
<xsl:when
test="translate(
substring-before(substring-after(@name, 'top '), ' holdings' ),
'0123456789*',
'') = '' ">
<!--code-->
</xsl:when>
</xsl:choose>
Upvotes: 1
Reputation: 70618
If you were using XSLT2.0 here, you could use the matches function which allows you to match text by means of a regular expression
<xsl:when test="matches(@name, '.*top \d+ holdings.*')">
On the other hand, if you were using XSLT 1.0, then the matches function is not available. One way you could do it in your very specific case is extract the text before "holdings" that occurs before "top" and check it is a number:
<xsl:when test="string(number(substring-before(substring-after(@name, 'top '), ' holdings' ) )) != 'NaN'">
Upvotes: 1