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

Re: Carrying Namespaces through a XSL to XSL Transform

Subject: Re: Carrying Namespaces through a XSL to XSL Transformation
From: "Kevin McCarthy" <Kevin@xxxxxxxxxxxx>
Date: Thu, 28 Dec 2000 20:57:20 -0800
xsl transform xmlns
Evan,

I have used the below example of xsl:text with disable-output-escaping when
applying an XSLT to an XML schema definition, to produce another XSLT. The
produced XSLT then has custom template matches, based upon the elements that
a paricular XML data file will contain. As I am working with multiple
namespaces and schema definitions, a single XSLT to generate a custom XSLT
worked well for me.

I think you have some good suggestions below, but I am not sure that they
will work for my situation.
-Kevin
----- Original Message -----
From: "Evan Lenz" <elenz@xxxxxxxxxxx>
To: <xsl-list@xxxxxxxxxxxxxxxxxxxxxx>
Sent: Thursday, December 28, 2000 8:30 PM
Subject: RE:  Carrying Namespaces through a XSL to XSL Transformation


> I agree that disable-output-escaping should not be used in this case.  The
> only defensible use of disable-output-escaping that I remember seeing is
the
> rendering of non-well-formed HTML in a browser (where the HTML markup is
> actually content, not markup).
>
> But there still is a problem here.  Namespace nodes found only in the
source
> tree are only copied to the result tree when nodes from the source tree
are
> copied.  If the stylesheet you're generating doesn't copy those nodes from
> the source tree, the namespace nodes won't be copied either.  (When
> namespace nodes are copied, you apparently can trust the resulting
declared
> prefixes to be the same as that of the source --
> http://www.biglist.com/lists/xsl-list/archives/200010/msg00206.html)
>
> A better solution to this problem can be found by temporarily copying an
> element in the source tree for which all the desired namespace
declarations
> are in scope.  Within that copied element, you can then produce the rest
of
> your stylesheet.  The final step, of course, is to extract the produced
> stylesheet from this temporary root element.  This requires use of the
> node-set function, or another XSLT transformation.  (Incidentally, I seem
to
> remember finding that the node-set solution was extremely slower, when
using
> SAXON and a large stylesheet, than serializing, parsing, and doing another
> transformation, but that's another issue, particularly interesting with
> regard to v1.1 eliminating the need for the node-set function
> altogether--maybe Mike Kay can address this, but I continue to digress...)
>
> Here's an example that assumes all required namespace declarations will be
> found on the root element of the source tree (you can experiment with the
> three template rules provided by changing the modes):
>
> <xsl:stylesheet version="1.0"
>   xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>   xmlns:saxon="http://icl.com/saxon"
>   xmlns:out="http://xyzfind.com/dummy">
>
>   <xsl:namespace-alias stylesheet-prefix="out"
>                        result-prefix="xsl"/>
>
>   <!-- this one creates a temporary tree to
>        propagate source tree namespace declarations -->
>   <xsl:template match="/xsl:stylesheet">
>     <xsl:variable name="tempTree">
>       <xsl:copy>
>         <out:stylesheet version="1.0">
>           <!-- produce the stylesheet -->
>         </out:stylesheet>
>       </xsl:copy>
>     </xsl:variable>
>     <xsl:copy-of select="saxon:node-set($tempTree)/*/*"/>
>   </xsl:template>
>
>   <!-- this version works, but
>        requires another transformation -->
>   <xsl:template match="/xsl:stylesheet"
>                 mode="requiresSubsequentTransformation">
>     <xsl:copy>
>       <out:stylesheet version="1.0">
>         <!-- produce the stylesheet -->
>       </out:stylesheet>
>     </xsl:copy>
>   </xsl:template>
>
>   <!-- this is probably what you tried that didn't work -->
>   <xsl:template match="/xsl:stylesheet"
>                 mode="failedAttempt">
>     <out:stylesheet version="1.0">
>       <!-- produce the stylesheet -->
>     </out:stylesheet>
>   </xsl:template>
>
> </xsl:stylesheet>
>
>
> Here's the *source* document:
>
> <xsl:stylesheet version="1.0"
>   xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>   xmlns:a="http://www.namespace.we.want.to.propagate">
>
>   <xsl:template match="a:stuff">
>     <!-- stuff -->
>   </xsl:template>
>
> </xsl:stylesheet>
>
>
> Here's the (desired) result:
>
> <xsl:stylesheet version="1.0"
>   xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>   xmlns:a="http://www.namespace.we.want.to.propagate"/>
>
>
> But this approach only works when you know where the namespace
declarations
> are (at the root element of the source document, in this case).  It breaks
> down when you move the namespace declarations in the source around like
so:
>
> <xsl:stylesheet version="1.0"
>   xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
>
>   <xsl:template match="a:stuff"
> xmlns:a="http://www.namespace.we.wanted.to.propagate">
>     <!-- stuff -->
>   </xsl:template>
>
> </xsl:stylesheet>
>
>
> Again, it will only work if the nodes for which the desired namespaces are
> in scope are copied to the result.
>
> Thus, this isn't a perfect solution.  For now, I'm guessing the solution
is
> to copy as much as possible (as opposed to using literal result elements)
> and test the result to make sure it worked (yuck!)  It's been a while
since
> I've implemented real applications of this, so if I'm missing something,
I'd
> love to hear it!  I do feel that I'm missing something...
>
> Evan Lenz
> elenz@xxxxxxxxxxx
> http://www.xyzfind.com
> XYZFind -- Repository, Search, and Query for XML
> Download our free beta software: http://www.xyzfind.com/beta
>
>
> > -----Original Message-----
> > From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> > [mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx]On Behalf Of Kevin
> > McCarthy
> > Sent: Wednesday, December 27, 2000 7:39 PM
> > To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> > Cc: chadsm@xxxxxxxxx
> > Subject: Re:  Carrying Namespaces through a XSL to XSL
> > Transformation
> >
> >
> > Chad,
> >
> > Here is a template that I have used in the past, using MSXML3.
> > This successfully outputs multiple namespace references in the resulting
> > XSLT.
> > I am using parameters in the below example to define on of my
> > namespaces and
> > schema locations.
> >
> > Good luck,
> > -Kevin
> >
> >
> >
> > <!--
> >  renderXSLStylesheetStart:
> >   renders the opening xsl:stylesheet tag and attrs
> > -->
> > <xsl:template name="renderXSLStylesheetStart">
> > <xsl:text disable-output-escaping="yes">&#60;&#63;xml
> > version="1.0"&#63;&#62;</xsl:text>
> > <xsl:text disable-output-escaping="yes">
> > &#60;xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
> > version="1.0"</xsl:text>
> >   xmlns:s="urn:schemas-microsoft-com:xml-data"
> >   xmlns:dt="urn:schemas-microsoft-com:datatypes"
> >   xmlns:<xsl:value-of select="$ns"
> > />="x-schema:http://localhost/schema/<xsl:value-of select="$name"
> > />Schema.xml"
> >   xmlns:editA="x-schema:http://localhost/schema/EditAttributes.xml"
&#62;
> > </xsl:text>
> > </xsl:template>
> >



 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.