xsl-list
[Top] [All Lists]

Re: [xsl] xmlns=""

2011-02-22 08:15:56
Merrilees, David wrote:

When I add a default namespace to an element, it's direct descendants acquire an 
xmlns="". Does anyone know why this is, or how to avoid it?

Input:

<?xml version="1.0" encoding="UTF-8"?>
<html>
         <head>
                 <title>Vítejte</title>
         </head>
         <body id="home">
         <body>
</html>

XSL:

<xsl:template match="/html">
         <html xmlns="http://www.w3.org/1999/xhtml";>
                 <xsl:sequence select="./node()"/>
         </html>
</xsl:template>

Output:

<?xml version="1.0" encoding="UTF-8"?>
<html xmlns="http://www.w3.org/1999/xhtml";>
         <head xmlns="">

The input element you copy has no namespace thus in the new document to preserve that information the serializer adds the xmlns="". If you want to put your input elements that are in no namespace into the XHTML namespace then you need to do that for each result element you create.

So instead of doing xsl:copy or copy-of or sequence to copy elements from the input to the output you need to use apply-templates with e.g.
  <xsl:template match="*">
<xsl:element name="{local-name()}" namespace="http://www.w3.org/1999/xhtml";>
      <xsl:apply-templates/>
    </xsl:element>
  </xsl:template>


--

        Martin Honnen
        http://msmvps.com/blogs/martin_honnen/

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>