|
[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
> 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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








