-2

Hi,

How I could fetch first three character from a string variable.
Say for I fetched a variable message="ABCtest" .... now I want to test that the first three character matches ABD or not .. How I could code to achieve in xslt?

Cheers
Manish

3
Contributors
2
Replies
4
Views
8 Years
Discussion Span
Last Post by m.asfak
1

Hi,

How I could fetch first three character from a string variable.
Say for I fetched a variable message="ABCtest" .... now I want to test that the first three character matches ABD or not .. How I could code to achieve in xslt?

Cheers
Manish

I am giving answer focusing on the bold line (that I've made)....

Let's consider the following example

<?xml version="1.0" encoding="UTF-8"?>
<abc>
    <def>        
    </def>
    <ghi>
        <jkl>ABCdef</jkl>        
    </ghi>
    <jkl/>
</abc>

I want to print ABCdef if it contain ABC in the first three letters....

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
    <xsl:template match="/">
        <xsl:apply-templates/>
    </xsl:template>
    
    <xsl:template match="jkl">
        <xsl:if test="substring(.,1,3)='ABC'">
            <xsl:value-of select="."/>
        </xsl:if>
    </xsl:template>
    
</xsl:stylesheet>

Hope you will get the answer.

Regards.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.