RE: [xsl] Perpetuating xsl instructions

Subject: RE: [xsl] Perpetuating xsl instructions
From: "Lars Huttar" <lars_huttar@xxxxxxx>
Date: Mon, 12 May 2003 17:14:17 -0500
> I have a need that requires appending the contents of 
> multiple xml documents
> at the end of a single style sheet - the same style sheet 
> that is making the
> transformations. So as this style sheet transforms the first 
> xml document,
> it needs to retain its instruction for the next xml.
> Here is my style sheet (these lines need to be present for each
> transformation):
> <xsl:output method="xml" indent="yes"/>
>     <xsl:template match="/">
>         <xsl:apply-templates select="*"/>
>     </xsl:template>
>     <xsl:template match="*">
>         <xsl:copy-of select="."/>
>         <!-- appended xml documents go (grow) here. -->
>     </xsl:template>

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="";
    xmlns:my=""; >
  <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:template match="node()|@*">
      <xsl:apply-templates select="@*"/>

  <xsl:template match="xsl:stylesheet">
    <xsl:param name="source-doc" />
      <xsl:apply-templates select="@*"/>
        <xsl:copy-of select="$source-doc" />
  <!-- XML docs get inserted here -->


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.


 XSL-List info and archive:

Current Thread