josephmmorgan@hotmail.com Posted March 27, 2013 Share Posted March 27, 2013 I have a peculiar situation where I need to be able to extract the namespace and the name of the first element within the "Body" tag of a soap envelope without knowledge of the soap namespace or the name of the namespace nor the element name within the body. The soap envelope can come in many ways. For examples: <S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"> <S:Body> <I_Need_This_One xmlns="king.kong.loves.godzilla"> <anythingElseDownHere> </anythingElseDownHere> </I_Need_This_One> </S:Body></S:Envelope> or <Soap:Envelope xmlns:Soap="http://schemas.xmlsoap.org/soap/envelope/"> <Soap:Body> <I_Need_This_One xmlns="king.kong.loves.godzilla"> <anythingElseDownHere> </anythingElseDownHere> </I_Need_This_One> </Soap:Body></Soap:Envelope> or <Mothra:Envelope xmlns:Mothra="http://schemas.xmlsoap.org/soap/envelope/"> <Mothra:Body> <I_Need_This_One xmlns="king.kong.loves.godzilla"> <anythingElseDownHere> </anythingElseDownHere> </I_Need_This_One> </Mothra:Body></Mothra:Envelope> And I need the XPath to extract both "I_Need_This_One" and "king.kong.loves.godzilla" into XSL variables. I've tried all kinds of variants of "/*/*[local-name()=Body]/*[local-name()]", and "//*[local-name()=Body]/*[local-name()]", but all I seem to get is everything below "anythingElseDownHere". So, I'm lost as to what to do. Link to comment Share on other sites More sharing options...
nrawat2005 Posted April 11, 2013 Share Posted April 11, 2013 Try this one:<?xml version="1.0" ?><xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"><xsl:template match="S:Body"> <xsl:variable name="firstChildName" select="child::*[1]/name()"/> <xsl:variable name="firstChildNameSpace" select="namespace-uri(child::*[1])"/> ChildName := <xsl:value-of select="$firstChildName"/> ChildNameSpace := <xsl:value-of select="$firstChildNameSpace"/></xsl:template></xsl:stylesheet> Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now