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

Dynamic pipelining in XSLT 2.0 w/ Saxon extensions

Subject: Dynamic pipelining in XSLT 2.0 w/ Saxon extensions
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Mon, 18 Jun 2007 17:19:54 -0400
 Dynamic pipelining in XSLT 2.0 w/ Saxon extensions

One of the niftier extensions available in the Saxon library is one that allows a stylesheet to be compiled and applied dynamically.

As its designer undoubtedly anticipated, it can even provide the basis for at least a lightweight pipelining infrastructure. The stylesheet below allows the specification of a set of stylesheets to be run in sequence over the input. Presently the stylesheets are named in a top-level variable, though of course this spec could also be external (and more fully-featured). Given the variable

  <xsl:variable name="processes">

the stylesheets "stylesheets/one.xsl", "stylesheets/two.xsl" and "stylesheets/three.xsl" (relative to the pipelining stylesheet) are run in series over the input document, until either a "done" element is encountered, or there are no more steps. (The "path" element may be omitted; if used it must currently appear first.)

My questions:

* This runs (tested under the current Saxon 8.9), but how will it scale? In particular, Mike Kay may be able to say whether compiled stylesheets are be cached when this is run over a set of documents. If not, wouldn't compiling each stylesheet anew for each input document be an impediment?

* Are there any obvious pitfalls or problems with this approach? (Or any not so obvious?) How does it compare to other methods?

(So far I can say only that it's really easy to use, but again I'm not sure it will scale as well as other methods. It does have the advantage, it appears, of avoiding serialization altogether until the last step.)

The stylesheet:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"

<xsl:output method="xml"/>

<!-- Saxon pipelining stylesheet:

Takes document input and passes it through a chain of transformations

The steps will run in order until a "done" element is encountered or they run out


  <xsl:variable name="processes">

  <xsl:template match="/">
    <xsl:apply-templates select="$processes/m:step[1]">
      <xsl:with-param name="in" select="/"/>

<xsl:template match="m:step">
<xsl:param name="in"/>
<xsl:param name="stylesheet" select="concat($processes/m:path,.)"/>
<xsl:variable name="out">
<xsl:variable name="process" select="saxon:compile-stylesheet(doc($stylesheet))"/>
<xsl:apply-templates select="saxon:transform($process,$in)" mode="annotate">
<!-- 'annotate' mode will provide the result with local annotations -->
<xsl:with-param name="stylesheet" select="$stylesheet"/>
<!-- If you don't want the result annotated, simply use
<xsl:copy-of select="saxon:transform($process,$in)"/> -->
<xsl:if test="empty(following-sibling::*[1])">
<xsl:copy-of select="$in"/>
<xsl:apply-templates select="following-sibling::*[1]">
<xsl:with-param name="in" select="$out"/>

  <xsl:template match="m:done">
    <xsl:param name="in"/>
    <xsl:copy-of select="$in"/>

  <xsl:template match="/" mode="annotate">
    <xsl:param name="stylesheet" select="'not given'"/>
      <!-- adding a comment to the top of the result -->
      <xsl:text> process run: </xsl:text>
      <xsl:value-of select="$stylesheet"/>
    <xsl:copy-of select="node()"/>


For testing, my one.xsl, two.xsl and three.xsl stylesheets all look like this (with adjustments):

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"

<xsl:template match="*">
  <xsl:element name="{local-name()}-one">
    <xsl:copy-of select="@*"/>

  <xsl:template match="comment() | processing-instruction()">
    <xsl:copy-of select="."/>


Comments welcome,

Wendell Piez                            mailto:wapiez@xxxxxxxxxxxxxxxx
Mulberry Technologies, Inc.                http://www.mulberrytech.com
17 West Jefferson Street                    Direct Phone: 301/315-9635
Suite 207                                          Phone: 301/315-9631
Rockville, MD  20850                                 Fax: 301/315-8285
  Mulberry Technologies: A Consultancy Specializing in SGML and XML

Current Thread


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.
First Name
Last Name
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.