sbutt 0 Newbie Poster

Hi Folks,
I have this following xslt script:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.2" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ibn="http://ibn.traveltainment.de/2009/001" xmlns="http://www.opentravel.org/OTA/2003/05" xmlns:ota="http://www.opentravel.org/OTA/2003/05" xmlns:ota1="http://www.opentravel.org/OTA/2002/11" xmlns:ns3="http://www.opentravel.org/OTA/2002/11" xmlns:fo="http://www.w3.org/1999/XSL/Format" exclude-result-prefixes="SOAP-ENV ota ns3">
	<xsl:output method="text" encoding="UTF-8"/>
	<xsl:variable name="soap" select="name(/SOAP-ENV:Envelope/SOAP-ENV:Body/ota:*)"/>
	<xsl:variable name="soap2" select="name(/soap:Envelope/soap:Body/ns3:*)"/>
	<xsl:variable name="base" select="name(/*)"/>
	<xsl:template match="/">
		<xsl:choose>
			<xsl:when test="count(soap:Envelope/soap:Body) > 0">
				<xsl:value-of select="$soap2"/>
				<xsl:value-of select="$soap"/>
			</xsl:when>
			<xsl:when test="count(SOAP-ENV:Envelope/SOAP-ENV:Body) > 0">
				<xsl:value-of select="$soap"/>
				<xsl:value-of select="$soap2"/>
			</xsl:when>
			<xsl:otherwise>
				<xsl:value-of select="$base"/>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>
</xsl:stylesheet>

in which I'm extracting the root element from inside the SOAP body, for example on a given Input:

<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:fo="http://www.w3.org/1999/XSL/Format">
	<soap:Header>
		<ns2:Security xmlns:ns2="http://schemas.xmlsoap.org/ws/2002/12/secext">
			<ns2:UsernameToken>
				<ns2:Username>xxxx</ns2:Username>
				<ns2:Password>vvvvv</ns2:Password>
				<Domain>aaa.bb.com</Domain>
			</ns2:UsernameToken>
		</ns2:Security>
	</soap:Header>
	<soap:Body>
		<ns3:SessionCreateRQ xmlns:ns3="http://www.opentravel.org/OTA/2002/11">
			<ns3:POS>
				<ns3:Source PseudoCityCode="AAA"/>
			</ns3:POS>
		</ns3:SessionCreateRQ>
	</soap:Body>
</soap:Envelope>

I get "ns3:SessionCreateRQ" as output, but I only need "SessionCreateRQ". That is "without" a namespace prefix.

How can i do that?

Similarly, I have other types of inputs as well and may be there I could have different namespace prefixes. I want to exclude them as well.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.