0

What is the XSL selector for a node value where an attribute can be upper or lower-case (or a combination)? Here is an example (I've stripped off much of the XML that isn't relevant). The first has an attribute of "NetworkID". The latter is "networkid". I need to get the value of the "Identity" node.

Attribute is "NetworkID".

<?xml version="1.0" encoding="UTF-8"?>
<cXML payloadID="1541780158582-6094783182107158181@216.109.111.67" timestamp="2018-11-09T08:15:58-08:00">
    <Header>
        <To>
            <Credential domain="networkid">
                <Identity>AN01000000000-T</Identity>
            </Credential>
        </To>
    </Header>
</cXML>

Attribute is "networkid".

<?xml version="1.0" encoding="UTF-8"?>
<cXML payloadID="1541780158582-6094783182107158181@216.109.111.67" timestamp="2018-11-09T08:15:58-08:00">
    <Header>
        <To>
            <Credential domain="NetworkID">
                <Identity>AN01000000000-T</Identity>
            </Credential>
        </To>
    </Header>
</cXML>

Is there a way to do this so that it ignores case?

<xsl:value-of select="Header/To/Credential[@domain='networkid']/Identity"/>

In my application, the above works in one case. I am forced to change it manually to get it to work in the other (but it breaks the prior).

anterys
  • 13
  • 1
  • 3
  • Can you use XSLT 2.0? – michael.hor257k Nov 09 '18 at 16:57
  • What would the 2.0 code be? I'm not sure to be honest. I've asked the vendor that question. – anterys Nov 09 '18 at 17:06
  • XSLT 2.0 has functions to convert a string to upper/lower case. The question is whether your XSLT processor supports XSLT 2.0. If you're not sure, find out - see here how: https://stackoverflow.com/questions/25244370/how-can-i-check-which-xslt-processor-is-being-used-in-solr/25245033?s=1|26.6139#25245033 – michael.hor257k Nov 09 '18 at 17:25
  • I'm being told that it does support 2.0. Do you know the selector code/syntax to use? – anterys Nov 09 '18 at 19:58

1 Answers1

0

If you can use XSLT 2.0, then replace your:

<xsl:value-of select="Header/To/Credential[@domain='networkid']/Identity"/>

with:

<xsl:value-of select="Header/To/Credential[lower-case(@domain)='networkid']/Identity"/>

In XSLT 1.0, define:

<xsl:variable name="upper-case" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'"/>
<xsl:variable name="lower-case" select="'abcdefghijklmnopqrstuvwxyz'"/>

then use:

<xsl:value-of select="Header/To/Credential[translate(@domain, $upper-case, $lower-case)='networkid']/Identity"/>
michael.hor257k
  • 113,275
  • 6
  • 33
  • 51
  • It appears we are not able to use version 2 (our vendor appears to have been wrong). How would you do this with 1.0? – anterys Nov 14 '18 at 15:40