[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Controlling namespace in output

Subject: Re: Controlling namespace in output
From: David Carlisle <davidc@xxxxxxxxx>
Date: Fri, 17 Dec 2010 09:30:56 +0000
Re:  Controlling namespace in output
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. ________________________________________________________________________


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.