Devdp
Devdp

Reputation: 11

How to get the value of xml node if namespace is prefix on it

I want to get the value of XML node using Xpath and XSLT. Below is the input XML and and my XSLT code.

Below is the request xml:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:nat="http://schemas.datacontract.org/2004/07/xyz.DigitalBanking.Service.Token" xmlns:urn="urn:xyz:ASML:2.0:assertion">
       <soapenv:Header/>
       <soapenv:Body>
          <nat:GetAdfsSAMLFromASML>

             <nat:request>

            <nat:applicationType>secure_inbox</nat:applicationType>
                <nat:department>Internet_Bank</nat:department>
                <nat:firstName>quae divum incedo</nat:firstName>
                <nat:lastName>verrantque per auras</nat:lastName>
                <nat:title>per auras</nat:title>
                <nat:emailaddress>[email protected]</nat:emailaddress>
                <nat:mejrgeOnAttribute>[email protected]</nat:mejrgeOnAttribute>
                <nat:ExistingASMLToken>

    </nat:ExistingASMLToken>
             </nat:request>
          </nat:GetAdfsSAMLFromASML>
       </soapenv:Body>
    </soapenv:Envelope>

Below is the xsl code :

 <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet version="1.0"
        xmlns:xalan="http://xml.apache.org/xalan"
        xmlns:pbdp="http://datapower.common.stp.pbds.pbit.jpmc.com" 
        xmlns:dpconfig="http://www.datapower.com/param/config"
        xmlns:nw="http://www.datapower.com/extensions/functions"
        xmlns:date="http://exslt.org/dates-and-times"
        xmlns:func="http://exslt.org/functions"
        xmlns:nat="http://schemas.datacontract.org/2004/07/xyz.DigitalBanking.Service.Token"      

        xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        >

        -->



        <xsl:template match="/">

            <xsl:variable name="c">'</xsl:variable>


            <xsl:variable name="applicationType" select="string(//*[local-name()='nat:GetAdfsSAMLFromASML']/@*[local-name()='nat:request']/@*[local-name()

    ='nat:applicationType'])"/>
                    <xsl:value-of-select= "$applicationType"/>


        </xsl:template>
    </xsl:stylesheet>

I would like to fetch the value of <nat:applicationType> . i.e. output should come secure_inbox.

I tried with above xslt but didn't get the desired output.

Upvotes: 0

Views: 294

Answers (1)

michael.hor257k
michael.hor257k

Reputation: 117140

The following stylesheet:

XSLT 1.0

<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:nat="http://schemas.datacontract.org/2004/07/xyz.DigitalBanking.Service.Token" 
exclude-result-prefixes="soapenv nat">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>

<xsl:template match="/">
    <result>
        <xsl:value-of select="/soapenv:Envelope/soapenv:Body/nat:GetAdfsSAMLFromASML/nat:request/nat:applicationType"/>
    </result>
</xsl:template>

</xsl:stylesheet>

when applied to your input example, will return:

<?xml version="1.0" encoding="UTF-8"?>
<result>secure_inbox</result>

Upvotes: 1

Related Questions