Re: [xsl] Controlling namespace in output

Subject: Re: [xsl] Controlling namespace in output
From: David Carlisle <davidc@xxxxxxxxx>
Date: Fri, 17 Dec 2010 09:30:56 +0000
On 17/12/2010 04:36, Peter Desjardins wrote:
That sounds like an excellent solution. Can you give an example of how
I can add the namespace to the stylesheet so that all elements are
generated in the DocBook namespace?


actually I hadn't noticed that you had posted code.

You need to do what I suggested (take
namespace=""; of the xsl:element as you don't want just that element in the namespace and add
to xsl:stylesheet so that elements generated in the stylesheet are in the tight namespace (whether you use literal elements or xsl:element)


<xsl:element name="section">
	<xsl:attribute name="version">5.0</xsl:attribute>
	<xsl:attribute name="xml:id">myIdentifier</xsl:attribute>

although that can be much more simply written as

<section version="5.0" xml;id="myIdentifier">

you only need to use xsl:element or xsl:attribute if the element/attribute names are being calculated at run time.

However you also need to do what ken suggested, of not using xsl:copy, as you don't want to copy the elements you need to change their name (from no namespace names to docbook names)

so change xsl:copy to xsl:apply-templates/>

and have a default rule of the form

<xsl:template match="*">
<xsl:element name="{local-name()}">
<xsl:copy-of select="@*"/>

note here is a case where you do need to use xsl:element as xsl;copy would preserve the full name including the namespace.


________________________________________________________________________ The Numerical Algorithms Group Ltd is a company registered in England and Wales with company number 1249803. The registered office is: Wilkinson House, Jordan Hill Road, Oxford OX2 8DR, United Kingdom.

This e-mail has been scanned for all viruses by Star. The service is
powered by MessageLabs. ________________________________________________________________________

Current Thread