Re: [xsl] Perpetuating xsl instructions

Subject: Re: [xsl] Perpetuating xsl instructions
From: Alan Gardner <scipiomedia@xxxxxxxxxxx>
Date: Mon, 12 May 2003 17:33:17 -0600
Lars - man you nailed it and didn't even know the whole purpose of the
project!!! In your honor we've named the stylesheet lars.xsl!

Thanks for the post, the solution is very elegant. Thanks again.

Alan


On 5/12/03 4:14 PM, "Lars Huttar" <lars_huttar@xxxxxxx> wrote:
> Do you really want your appended xml documents to go into the
> template that matches "*"??
> In other words do you want the result to be a stylesheet that
> will output all the so-far-appended XML documents once for every
> element of the new source document?
> 
> Maybe you really want the XML documents to be inserted somewhere
> else, perhaps after the end of the last template.
> (As your other email suggests.)
> 
> Maybe it would help if you explain your purpose... what are you trying
> to achieve by accumulating XML documents in your stylesheet?  What do you
> want to do with the stylesheet after you've run several xml documents
> through it?
> 
> Here is a stylesheet that does most of what (I think) you want:
> 
> 
> <?xml version="1.0" encoding="UTF-8"?>
> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
>   xmlns:my="http://www.my-dummy-namespace.org/lars/dummy"; >
> <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
> 
> <!-- self-replicating stylesheet:
>   When run on a source file, this stylesheet should produce itself, with the
>   contents of the source file inserted into it at a certain point. -->
> 
> <xsl:template match="/">
>   <xsl:apply-templates select="document('')/*">
>     <xsl:with-param name="source-doc" select="/" />
>   </xsl:apply-templates>
> </xsl:template>
> 
> <xsl:template match="node()|@*">
>   <xsl:copy>
>     <xsl:apply-templates select="@*"/>
>     <xsl:apply-templates/>
>   </xsl:copy>
> </xsl:template>
> 
> <xsl:template match="xsl:stylesheet">
>   <xsl:param name="source-doc" />
>   <xsl:copy>
>     <xsl:apply-templates select="@*"/>
>     <xsl:apply-templates/>
>     <my:doc>
>       <xsl:copy-of select="$source-doc" />
>     </my:doc>
>   </xsl:copy>
> </xsl:template>
> 
> <!-- XML docs get inserted here -->
> 
> </xsl:stylesheet>
> 
> 
> It's not a perfect replica -- you get a lot of extra whitespace
> with each transformation.
> 
> The reason the XML docs get put into a <my:doc> element is
> that if you put a namespaceless top-level element into a stylesheet,
> you get an error.
> 
> Lars
> 
> 
> XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
> 
> 


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


Current Thread