This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


> 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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]