XSLT: I don't get the xmlns in target

Rosa Mª Gómez Flores

Usenet Archive
Joined
Oct 11, 2003
Messages
1
Reaction score
0
Hallo!

I don't understand exactly what is the 'xmlns' attribute, nor why it have problems with the xmlns attribute of the sylesheet, but I need it in my output XML file. Could anybody tell me how to transform this input:

<ROOT-ELEMENT>
<SOHN>...</SOHN>
</ROOT-ELEMENT>

in this output:

<ROOT-ELEMENT xmlns="http://www.whatever">
<SOHN>...</SOHN>
</ROOT-ELEMENT>

Thanks a lot of,

Rgf
 

Martin Boehm

Usenet Archive
Joined
Sep 12, 2003
Messages
52
Reaction score
0
Could anybody tell me how to transform this input:
<ROOT-ELEMENT>
<SOHN>...</SOHN>
</ROOT-ELEMENT>

in this output:

<ROOT-ELEMENT xmlns="http://www.whatever">
<SOHN>...</SOHN>
</ROOT-ELEMENT>

<?xml version='1.0'?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/ROOT-ELEMENT"> <xsl:element name="ROOT-ELEMENT" namespace="http://www.whatever"> <xsl:copy-of select="./*"/> </xsl:element> </xsl:template> </xsl:stylesheet>

Martin
 

Richard Tobin

Usenet Archive
Joined
Jan 6, 2000
Messages
4,251
Reaction score
0
Rosa Mª Gómez Flores said:
I don't understand exactly what is the 'xmlns' attribute, nor why it have problems with the xmlns attribute of the sylesheet,

You might want to find out more before blindly pressing ahead, but this copies a document, placing all elements in the http://www.whatever namespace:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

<xsl:template match="*">
<xsl:element name="{local-name}" namespace="http://www.whatever"> <xsl:apply-templates select="node|@*"/> </xsl:element> </xsl:template>

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

</xsl:stylesheet>

-- Richard
 

Bob Foster

Usenet Archive
Joined
Aug 14, 2002
Messages
220
Reaction score
0
Dimitre Novatchev said:
This is not the correct solution -- the copied nodes will not belong to the namespace of ROOT-ELEMENT.

Here's a better one:

<xs:stylesheet xmlns:xs="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xs:eek:utput method="xml" omit-xml-declaration="yes"/> <xs:template match="*" priority="1.0"> <xs:element name="{name(.)}" namespace="http://example.com"> <xs:apply-templates select="@*|node"/> </xs:element> </xs:template> <xs:template match="@*|node"> <xs:copy> <xs:apply-templates select="@*|node"/> </xs:copy> </xs:template> </xs:stylesheet>

Bob Foster
 

Dimitre Novatchev

Usenet Archive
Joined
Nov 7, 2000
Messages
737
Reaction score
0
Here's a better one:

Yes, I already provided exactly the same in microsoft.public.xsl -- as I pointed to Rosa, no one would reply to her identical messages in 3 forums.

In microsoft.public.xml Marrow posted a slightly better one -- the default namespace is declared on the xsl:stylesheet element and does not need to be specified on the xsl:element instructions.

=====
Cheers,

Dimitre Novatchev.
http://fxsl.sourceforge.net/ -- the home of FXSL
 

Bob Foster

Usenet Archive
Joined
Aug 14, 2002
Messages
220
Reaction score
0
Dimitre Novatchev said:
In microsoft.public.xml Marrow posted a slightly better one -- the default namespace is declared on the xsl:stylesheet element and does not need to be specified on the xsl:element instructions.

I don't know how to do that. What does it look like?

Bob
 

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