[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] XMLNS problem


Subject: Re: [xsl] XMLNS problem
From: Michael Kay <mike@xxxxxxxxxxxx>
Date: Tue, 12 Feb 2013 21:54:18 +0000

On 12/02/2013 21:35, Eric Harbeson wrote:

This is close, but it doesn't include the xmlns line, which appears to be needed for it to validate correctly. The XSLT I have below seems like it should do what I want, but it produces an error in the xsl:namespace declaration.




     <xsl:template match="ead">
         <xsl:element name="ead">
             <xsl:namespace name="">urn:isbn:1-931666-22-9</xsl:namespace>
             <xsl:attribute name="xsi:schemaLocation">urn:isbn:1-931666-22-9
                 http://www.loc.gov/ead/ead.xsd</xsl:attribute>
             <xsl:apply-templates/>
         </xsl:element>
     </xsl:template>
...
</xsl:stylesheet>


The xsl:element instruction creates the ead element in no-namespace, and you then attempt to add a namespace node that binds the default namespace to "urn:isbn:1-.....". Adding a namespace node to an existing element can't change the name(space) of the element, and is an error if it's inconsistent with the name of the element. You need to create the element in the right namespace to start with, and then the namespace node will be created for you automatically:

<xsl:element name="ead" namespace="urn:isbn:1-931666-22-9">

Alternatively, use a literal result element:

<ead xmlns="urn:isbn:1-931666-22-9">

though this doesn't give you quite such detailed control over namespaces.

Michael Kay
Saxonica


Current Thread
Keywords