[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: Martin Honnen <Martin.Honnen@xxxxxx>
Date: Fri, 17 Dec 2010 13:18:20 +0100
Re:  Controlling namespace in output
Peter Desjardins wrote:

I rewrote my stylesheet so it transforms instead of copies. Is this
something like what you meant?

Peter

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
     <xsl:output method="xml" indent="yes"/>
     <xsl:template match="root">
         <xsl:element name="section" namespace="http://docbook.org/ns/docbook">
             <xsl:attribute name="version">5.0</xsl:attribute>
             <xsl:attribute name="xml:id">myIdentifier</xsl:attribute>
             <xsl:apply-templates />
         </xsl:element>
     </xsl:template>
     <xsl:template match="*">
         <xsl:variable name="elementName">
             <xsl:value-of select="name()" />
         </xsl:variable>
         <xsl:element name="{$elementName}"
namespace="http://docbook.org/ns/docbook">
             <xsl:for-each select="@*">
                 <xsl:copy-of select="." />
             </xsl:for-each>
             <xsl:apply-templates />
         </xsl:element>
     </xsl:template>
</xsl:stylesheet>

I would shorten that to


<xsl:stylesheet version="2.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns="http://docbook.org/ns/docbook">
    <xsl:output method="xml" indent="yes"/>

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

    <xsl:template match="root">
      <section version="5.0" xml:id="myIdentifier">
            <xsl:apply-templates />
      </section>
    </xsl:template>

</xsl:stylesheet>


--


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

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.