XSLT: I don't get the xmlns in target

  • Thread starter Rosa Mª Gómez Flores
  • Start date
R

Rosa Mª Gómez Flores

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
 
M

Martin Boehm

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
 
R

Richard Tobin

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
 
B

Bob Foster

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
 
D

Dimitre Novatchev

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
 
B

Bob Foster

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
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top