get node name from namespace

206 views Asked by At

this is my xml

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:end="http://endpoint.ggg.com/">

   <soapenv:Header/>
   <soapenv:Body>
      <end:onlineExpressRemit>
      <channelCode>NBPS</channelCode>
      </end:onlineExpressRemit>
   </soapenv:Body>
    </soapenv:Envelope>

and this is my xslt

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
xmlns:end="http://endpoint.ggg.com/" >

    <xsl:template match="/">
<xsl:value-of name="ggg2" select="/soapenv:Envelope/soapenv:Body/*[namespace-uri()]"/>
    </xsl:template>
</xsl:stylesheet>

my expected output is display only

onlineExpressRemit

i am very new for xslt, i try name(), local-name() alot others method, however no luck, i cant retrieve only node-name, any help will do, thank you!

1

There are 1 answers

0
har07 On BEST ANSWER

You can try using local-name(soapenv:Envelope/soapenv:Body/*), for example, the following XSL transformation :

<xsl:stylesheet version="1.0" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
    xmlns:end="http://endpoint.ggg.com/" >

    <xsl:output method="text" omit-xml-declaration="yes"/>

    <xsl:template match="/">
        <xsl:element name="root">
            <xsl:value-of select="local-name(soapenv:Envelope/soapenv:Body/*)"/>
        </xsl:element>
    </xsl:template>
</xsl:stylesheet>

when applied to your XML sample, yield the following output :

<root>onlineExpressRemit</root>

Note: I added <root> element just because in online XSLT processor I used for testing, there was error when root element is absent. Usually, setting <xsl:output> is enough to be able to output a non-XML result : XSLT: Transforming into non-xml content?