Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

XSLT: problem with the xmlns in target

0 views
Skip to first unread message

Rosa Mª Gómez Flores

unread,
Oct 11, 2003, 3:23:59 PM10/11/03
to
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


Scott M.

unread,
Oct 12, 2003, 10:57:36 PM10/12/03
to
<ROOT-ELEMENT>
<xsl:attribute name="xmlns">http://www.whatever.com</xsl:attribute>
</ROOT-ELEMENT>

The xmlns attribute is how you associate an xml tag with an xml namespace.
Some namespaces are pre-defined by the w3c (World Wide Web Consortium) and
MUST be referenced correctly or your xml parser won't know what the special
tags in that namespace mean.

"Rosa Mª Gómez Flores" <fili...@auna.com> wrote in message
news:%23MzbszC...@TK2MSFTNGP11.phx.gbl...

Oleg Tkachenko

unread,
Oct 13, 2003, 7:56:54 AM10/13/03
to
Scott M. wrote:

> <ROOT-ELEMENT>
> <xsl:attribute name="xmlns">http://www.whatever.com</xsl:attribute>
> </ROOT-ELEMENT>

This won't work. xmlns (namespace declaration) is not treated as
attribute in XPath/XSLT data model, so one cannot create namespace
declaration using xsl:attribute instruction, see
http://www.w3.org/TR/xslt#creating-attributes

The solution is to use xsl:element instruction to create new elements in
the namespace.
--
Oleg Tkachenko
http://www.tkachenko.com/blog
Multiconn Technologies, Israel

Marrow

unread,
Oct 13, 2003, 3:52:00 PM10/13/03
to
Hi,

Try an identity transform with a default output namespace, something like...

<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns="http://www.whatever">
<xsl:output method="xml"/>

<xsl:template match="/">
<xsl:apply-templates/>
</xsl:template>

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

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

Hope this helps
Marrow
http://www.marrowsoft.com - home of Xselerator (XSLT IDE and debugger)
http://www.topxml.com/Xselerator


"Rosa Mª Gómez Flores" <fili...@auna.com> wrote in message
news:%23MzbszC...@TK2MSFTNGP11.phx.gbl...

0 new messages