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

RE: Perpetuating xsl instructions

Subject: RE: Perpetuating xsl instructions
From: "Lars Huttar" <lars_huttar@xxxxxxx>
Date: Mon, 12 May 2003 17:14:17 -0500
xsl copy sheet
> 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="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


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.