Simple xslt question

J

jon.harding

Hi, I have XML that looks like this

<xml version="1.0" encoding="UTF-8">
<Foo xmlns:xsi:=htttp;//www.w3.org/2001/etc>
<Baa1>
<Baa11>baa</Baa11>
<Baa12>baa</Baa12>
</Baa1>
<Baa3>
<Baa38>baa</Baa38>
</Baa3>
<Baa4>baa</Baa4>
</Foo>

and what I want to turn it in to with xslt is

<Foo>
<Baa1>
<Baa11>baa</Baa11>
<Baa12>baa</Baa12>
</Baa1>
<Baa3>
<Baa38>baa</Baa38>
</Baa3>
<Baa4>baa</Baa4>
</Foo>

with generic xslt. The XML will have a different structure, the root
nodes won't always be Foo and the children won't always look like Baa,
they will always be different. My requirement is to strip out the
namespaces and <?xml etc> in a generic sense.

Is it possible to write generic xslt to strip out all namespaces (ALL
OF THEM, and some elements in the XML tree may have other namespaces
that are not w3.org) and <?xml xxxxx> leaving everything else in there

Thank you for your help

Jon
 
M

Mayeul

with generic xslt. The XML will have a different structure, the root
nodes won't always be Foo and the children won't always look like Baa,
they will always be different. My requirement is to strip out the
namespaces and<?xml etc> in a generic sense.

Is it possible to write generic xslt to strip out all namespaces (ALL
OF THEM, and some elements in the XML tree may have other namespaces
that are not w3.org)

Sure:

<xsl:template match="*">
<!-- Create element with same local name and no namespace -->
<xsl:element name="{local-name()}">
<!-- Add the attributes and apply the same to the children -->
<xsl:apply-templates select="@*|node()"/>
</xsl:element>
</xsl:template>

<xsl:template match="@*">
<!-- Create attribute with same local name and value -->
<xsl:attribute name="{local-name()}"><xsl:value-of
and<?xml xxxxx> leaving everything else in there

Theoretically that's what

<xsl:eek:utput method="xml" omit-xml-declaration="yes"/>

is about.
But XML toolchains have an habit of randomly reinserting the XML
declaration here and there, and therefore you'll sometimes find it back
in the produced document anyway. It all depends on your toolchain.
 
J

Joe Kesselman

Possible? Yes. Wise? Almost never.

Namespaces are part of the semantics of the document. Remove them and
the meaning of the document changes. Consider them a shorthand
replacement for including the URI in every instance of the name.
 

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

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,044
Latest member
RonaldNen

Latest Threads

Top