0

Hi I have field <name>ATTN Dani</name>,I need to remove the ATTN but it comes ATTN sometimes attn or Attn and even ATtn how can I do substring on this I have done the below xslt but its affecting the value.I dont want the value to be affected

<xsl:stylesheet version='2.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform' xmlns:pfx4="http://xmlns.oracle.com/apps/otm" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <xsl:output method="xml" indent="yes"/>
    <xsl:template match="/">
        <PARTNER_INBOUND_V2>

        <xsl:choose>

                    <xsl:when test="starts-with(upper-case(//root/name), 'ATTN')">
                        <IS_ACTIVE>Working</IS_ACTIVE>
                    <test><xsl:value-of select="normalize-space(substring-after(upper-case(//root/name),'ATTN'))"/></test>
                    </xsl:when>
                    <xsl:otherwise>
                        <IS_ACTIVE>Y</IS_ACTIVE>
                    </xsl:otherwise>

        </xsl:choose>
            </PARTNER_INBOUND_V2>
    </xsl:template>
</xsl:stylesheet>
Satheesh Kumar
  • 797
  • 7
  • 31
  • You can try using `translate()` to convert the string to upper or lower case and than compare. See this: http://stackoverflow.com/questions/586231/how-can-i-convert-a-string-to-upper-or-lower-case-with-xslt – dc95 May 19 '16 at 19:41
  • 2
    Incidentally, in your specific example here it, you're never going to have a name beginning with `"ATTN"`, as it's in a `` block that specifically requires it to start with `"C/O"`, unless you have more than one `name` element as a child of root. – Flynn1179 May 19 '16 at 20:39
  • 1
    Your stylesheet says version 1.0, but `upper-case()` requires XSLT 2.0. One more confusing thing in your question. – michael.hor257k May 19 '16 at 20:58

2 Answers2

2

Converting to upper/lower case is usually done with the translate method in XSLT 1.0. It's generally not 100% suitable as you have to specify exactly what letters to switch the case of, which can vary with language, but for language-agnostic applications, it's fine, and you can even cut down to just what you need:

substring-after(translate(.,'atn','ATN'), 'ATTN')

However, in your case this might be slightly risky, as you'll also convert letters in anything that comes after it.

Realistically, you're probably going to need

<xsl:if test="translate(substring(//root/name,1,5),'atn','ATN') = 'ATTN '">
  <xsl:value-of select="substring-after(//root/name,' ')"/>
</xsl:if>

Note the space at the end of the string that you're comparing with, that just makes sure there IS a space afte the 'ATTN', and then you can just substring-after that space to get what you need.

Flynn1179
  • 11,925
  • 6
  • 38
  • 74
0

If you know the string starts with "ATTN " but not sure of the case, you could use:

<xsl:value-of select="substring(name, 6)" />

to extract the subsequent substring.

michael.hor257k
  • 113,275
  • 6
  • 33
  • 51