Use ends with in XSLT v1.0

Viewed 33348

I am trying to edit a current XSLT. The functionality I want is when the value of "//code_no" ends with 01 I want to edit the current city location. Currently this functionality does not exist. I have tried using string and substring but it gives me an error saying ends with functionality does not exist. Please help

The value coming from the xml is

<code_no>
1870410001
</code_no>

in the xsl, I want to print this when the value ends with 01.

<td align="left" width="33%"><SPAN style="font-size: 12pt; font-family: Arial;">
    <a> <b><u><xsl:value-of select="//city"/>, <xsl:value-of select="//state"/> 
    </u></b></a></SPAN></td>
6 Answers

I know this question is actually an old one, but now I was looking for the same.

However, in the end I came up with something else that may be used by someone in the future.

Please see this:

contains(concat($str1, '$'), concat($str2, '$'))

Fast, simple, no calculation required.

Example of use:

    <xsl:variable name="str1" select="string('Some text to test.')" />
    <xsl:variable name="str2" select="string('test.')" />

    <xsl:if test="contains(concat($str1, '$'), concat($str2, '$'))">
        <xsl:value-of select="concat('Yes, text: &quot;', $str1, '&quot; ends with: &quot;', $str2, '&quot;.')"/>
    </xsl:if>

Of course you can use any sign instead of $ for concat() function.

In special cases, if you know that some character can not be contained in tag for example § you can do this:

<xsl:if test="contains(concat(code_no,'§'),'01§')">
  <td align="left" width="33%"><SPAN style="font-size: 12pt; font-family: Arial;">
    <a> <b><u><xsl:value-of select="//city"/>, <xsl:value-of select="//state"/> 
    </u></b></a></SPAN></td>
</xsl:if>
Related