xsl-list
[Top] [All Lists]

Re: [xsl] Controlling namespace in output

2010-12-17 03:31:12
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?

Thanks.


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

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

so

<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="@*"/>
<xsl:apply-templates/>
</xsl:element>
</xsl:template>

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

David


________________________________________________________________________
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. ________________________________________________________________________

--~------------------------------------------------------------------
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>