josephmmorgan@hotmail.com 0 Posted March 27, 2013 Report 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. Quote Link to post Share on other sites
nrawat2005 0 Posted April 11, 2013 Report 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> Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.