how to get the identity transformation to stop outputting extra 'xmlns:' attrib ? _clb_

Chris Bedford

Usenet Archive
Joined
Mar 18, 2002
Messages
18
Reaction score
0
Hi:

this question has been driving me crazy. would be grateful for any help.

I am writing a version of the identity transformation to filter some documents (they happen to be wsdl docs). My problem is that for just about every element in the output document all of the namespace defintions defined in my top level element are emitted.

This makes for a very cluttered document. I'm wondering how i can surpress of the emission of these xmlns attributes from the output tree.

here is a simple example:

INPUT XML DOC:

<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:uang-bpws="http://www.siebel.com/uangrammar/2002/03/bpel4ws/" name="tfXWidgetSrc_WSDL" targetNamespace="http://www.o.com/">

<wsdl:import pig="dog"/>
<book xmlns:blah="urn:foo"/>
</wsdl:definitions>

XSLT DOC:

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" > <xsl:template match="node"> <xsl:copy> <xsl:apply-templates select="@*|node"/> </xsl:copy> </xsl:template>

<xsl:template match="@*[ not ( starts-with(name,'xmlns:') ) ]"> <xsl:copy-of select="."/> </xsl:template>

<xsl:template match="wsdl:definitions">
<wsdl:BLAH>
<xsl:apply-templates select="@*|node"/>
</wsdl:BLAH>
</xsl:template>

</xsl:stylesheet

RESULT:

<?xml version="1.0" encoding="UTF-8"?>
<wsdl:BLAH xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" name="tfXWidgetSrc_WSDL" targetNamespace="http://www.o.com/">

<wsdl:import xmlns:uang-bpws="http://www.siebel.com/uangrammar/2002/03/bpel4ws/" pig="dog"/> <book xmlns:uang-bpws="http://www.siebel.com/uangrammar/2002/03/bpel4ws/" xmlns:blah="urn:foo"/> </wsdl:BLAH>

Observations:

the output tree includes xmlns: attributes in both the wsdl:import tag and the book tag.... even though they were not defined in the input doc to begin with.

I tried to surpress the xmlns: attributes with
@*[ not ( starts-with(name,'xmlns:') ) ]
but that works the same as vanilla
@*

any advice much appreciated.
-chris
 

Ben Edgington

Usenet Archive
Joined
Mar 18, 2004
Messages
45
Reaction score
0
I am writing a version of the identity transformation to filter some documents (they happen to be wsdl docs). My problem is that for just about every element in the output document all of the namespace defintions defined in my top level element are emitted.

This makes for a very cluttered document. I'm wondering how i can surpress of the emission of these xmlns attributes from the output tree.

RESULT:

<?xml version="1.0" encoding="UTF-8"?>
<wsdl:BLAH xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" name="tfXWidgetSrc_WSDL" targetNamespace="http://www.o.com/">

<wsdl:import xmlns:uang-bpws="http://www.siebel.com/uangrammar/2002/03/bpel4ws/" pig="dog"/> <book xmlns:uang-bpws="http://www.siebel.com/uangrammar/2002/03/bpel4ws/" xmlns:blah="urn:foo"/> </wsdl:BLAH>

Observations:

the output tree includes xmlns: attributes in both the wsdl:import tag and the book tag.... even though they were not defined in the input doc to begin with.

This seems to be processor dependent. With Sablotron I get the same result as you, whereas xsltproc gives the result

<wsdl:BLAH xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" name="tfXWidgetSrc_WSDL" targetNamespace="http://www.o.com/">

<wsdl:import pig="dog"/>
<book xmlns:blah="urn:foo"/>
</wsdl:BLAH>

I am no namespace expert, but the latter would seem to be more sensible. Which is *correct* I have no idea.

If you want to copy all of the input nodes into your output namespace then you must avoid using <xsl:copy/> and <xsl:copy-of/> and make new versions of all elements to be copied. This pair of templates applies the identity-without-namespaces transformation:

<xsl:template match="node">
<xsl:element name="{name}">
<xsl:apply-templates select="@*|node"/>
</xsl:element>
</xsl:template>

<xsl:template match="@*|text|comment|processing-instruction"> <xsl:copy/> </xsl:template>

Ben
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
548,042
Messages
3,104,223
Members
248,131
Latest member
Tonypshaw1

Latest Threads

Top