Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Namespace issue....I give up.

Status
Not open for further replies.

aswolff

Programmer
Jul 31, 2006
100
US
I've searched and searched and cannot figure it out.
I have a SOAP service that returns the following document:

Code:
<?xml version="1.0" encoding="UTF-8"?>
<CallCreateResponse  xmlns="[URL unfurl="true"]http://www.vendor.com.au/IN_RULES80/API">[/URL]
    <CallCreateResult>
        <nCallNumber>0</nCallNumber>
        <sMessage>Please Delete Name Space</sMessage>
        <Ret>NAME_SPACE_ERROR</Ret>
    </CallCreateResult>
</CallCreateResponse>

I need to transform this type of document(and several others) and get rid of the Namespace declaration) to below:

Code:
<?xml version="1.0" encoding="UTF-8"?>
<CallCreateResponse>
    <CallCreateResult>
        <nCallNumber>0</nCallNumber>
        <sMessage>Please Delete Name Space</sMessage>
        <Ret>NAME_SPACE_ERROR</Ret>
    </CallCreateResult>
</CallCreateResponse>

The following XSLT does not work
Code:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="[URL unfurl="true"]http://www.w3.org/1999/XSL/Transform"[/URL] version="1.0">
    <xsl:output method="xml" indent="yes" encoding="UTF-8"/>
    <xsl:template match="/*[local-name()='CallCreateResponse']">
        <CallCreateResponse>
            <xsl:copy-of select="/*[local-name()='CallCreateResponse']/*"/>
        </CallCreateResponse>
    </xsl:template>
</xsl:stylesheet>

Thanks in advance!
 
You can do it like this.
[1] Device as usual an identity transformation/templates.
[2] Device an element node template specifically set the element name.
[3] Add the exclude-result-prefixes to xsl:stylesheet element and assign it a value of #default.

Concretely, like this.
[tt]
<?xml version="1.0" ?>
<xsl:stylesheet version="1.0" xmlns:xsl=" exclude-result-prefixes="#default">
<xsl:eek:utput method="xml" indent="yes" version="1.0" encoding="utf-8" />
<!-- one form of identity transformation -->
<xsl:template match="/">
<xsl:apply-templates select="*" />
</xsl:template>
<xsl:template match="*|@*|text()|comment()|processing-instruction()">
<xsl:copy>
<xsl:apply-templates select="*|@*|text()|comment()|processing-instruction()" />
</xsl:copy>
</xsl:template>

<!-- more specific on element node: adding priority to increase safety factor, it is not obligatory in this case. -->
<xsl:template match="*" priority="10">
<xsl:element name="{name()}">
<xsl:apply-templates select="*|@*|text()|comment()|processing-instruction()" />
</xsl:element>
</xsl:template>

</xsl:stylesheet>
[/tt]
 
Does not seem to work....the below xslt still copies the namespace declaration. Am I doing something wrong?
Code:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="[URL unfurl="true"]http://www.w3.org/1999/XSL/Transform"[/URL] version="1.0" exclude-result-prefixes="#default">
    <xsl:template match="*|@*|text()|processing-instruction">
        <xsl:copy>
            <xsl:apply-templates select="*|@*|text()|processing-instruction"/>
        </xsl:copy>
    </xsl:template>
</xsl:stylesheet>
 
You have serious problem on concentration in reading people's advice. Did I not explicit enough? What warrant you to take out part of it?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top