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

Re: copying <xsl:stylesheet> tag to output xsl file

Subject: Re: copying <xsl:stylesheet> tag to output xsl file
From: Dimitre Novatchev <dnovatchev@xxxxxxxxx>
Date: Wed, 2 Jan 2002 08:16:39 -0800 (PST)
xsl stylesheet tag
> I have this XSL file as below..i want to copy the <xsl:stylesheet> tag to
> the output xsl file, as i need the "my" namespace declaration in the
> generated output xsl file.

In order to have ***just*** the namespace declaration in the output, you don't need
to copy the xsl:stylesheet node (or any element, on which the given namespace is
defined) from the stylesheet. All you have to do is just copy the namespace node
itself.

Bellow is a modified identity stylesheet, which copies the "my" namespace
declaration to the top element of its output:

copyNamespace.xsl:
-----------------
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:my="http://mysite.com/mynamespace"
>
    <xsl:output omit-xml-declaration="yes"/>
    <xsl:template match="/*">
      <xsl:copy>
        <xsl:copy-of select="document('')/*/namespace::*
                                             [name()='my']"/>
        <xsl:apply-templates select="@*|node()"/>

      </xsl:copy>
    </xsl:template>
    
    <xsl:template match="@*|node()">
      <xsl:copy>
        <xsl:apply-templates select="@*|node()"/>
      </xsl:copy>
    </xsl:template>
</xsl:stylesheet>

When applied with Saxon 6.5 on this sample source xml:

copyNamespace.xml:
-----------------
<t>
    <a>
        <b />
    </a>
    <c>
        <d />
    </c>
</t>

the result is:

<t xmlns:my="http://mysite.com/mynamespace">
    <a>
        <b/>
    </a>
    <c>
        <d/>
    </c>
</t>


Hope this helped.

Cheers,
Dimitre Novatchev.


__________________________________________________
Do You Yahoo!?
Send your FREE holiday greetings online!
http://greetings.yahoo.com

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


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.