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

Efficient Stylesheets for reordering

Subject: Efficient Stylesheets for reordering
From: Jose Alberto Fernandez <JFernandez@xxxxxxxxxxx>
Date: Tue, 7 Nov 2000 15:03:54 -0800
apply template select
Hi, I send this question originally to the XalanJ list, but I guess this is
a more appropriate forum.
I am trying to build templates that are suppose to reorder the nodes of an
input.
For example, given "doc1" grammar, we want to obtain "doc2" defined as
follows

<!ELEMENT doc1 (s1, s2, s3*, s4?, s5+) >
<!ELEMENT doc2 (s1, s3*, s4?, s2, s5+) >

Now, the simplest way to do this is with a template like:
 <xsl:template match="doc1" >
  <xsl:apply-template select="s1" />
  <xsl:apply-template select="s3" />
  <xsl:apply-template select="s4" />
  <xsl:apply-template select="s2" />
  <xsl:apply-template select="s5" />
 </xsl:template>
plus other templates that just copy the "s*" nodes just as they are.

Now, such template will wait until the whole document is read
before generating anything, because it does not know how many "s1"
can be in "doc1". One could inprove it be doing things like:

 <xsl:template match="doc1" >
  <xsl:apply-template select="s1[1]" />
  <xsl:apply-template select="s3" />
  <xsl:apply-template select="s4[1]" />
  <xsl:apply-template select="s2[1]" />
  <xsl:apply-template select="s5" />
 </xsl:template>

Here since we only need the first "s1" (it will be only one) we can start
generating output as soon as possible.
And start generating "s3"s as we see them, but for "s3" and "s4" we will
have to wait until the end of the document, if they are not actually present
(they are
optional).

Questions:

Am I completely wrong on my understanding of XSLT?

Is there some other way to write the template so that we can just stream out
most of the work? Notice that the only thing is needed to perform the
transformation is to
hold to the "s2" node as it is read, and put it back on the output just
before generating
the first "s5". The rest of the nodes can be just copied as they are from
input to output.

Are there any extensions that would allow discarding from memory those parts
of the original document that are no longer needed?

Now, I know that whether one gets actual streamming of the output depends on
the particular
implementation, but what I am interested here is on ways of writing the
stylesheet that will
not deminish the ability of an implementation to stream the output.

Hope you have some good ideas,

Jose Alberto


 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.