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

Re: How to cope with the complexity of an XSLT program

Subject: Re: How to cope with the complexity of an XSLT program with thousands of template rules?
From: "Chris Papademetrious christopher.papademetrious@xxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Thu, 2 Jun 2022 12:40:41 -0000
Re:  How to cope with the complexity of an XSLT program
Hi Roger,

Thousands!!? I get nervous when there's dozens of templates. :)  Thanks for
posting your favorite set of complexity-reducing tricks.

I had one stylesheet where I needed to inline some elements with @idref
references, then reorganize the resulting content. I tried doing everything in
one pass with clever use of <xsl:apply-templates> and <xsl:next-match>, but I
always seemed to mishandle some corner case.

I eventually gave in and implemented multiple passes:

  <!-- TOP-LEVEL PASS - apply passes 1 through 4 to document -->
  <xsl:template match="/">
    <xsl:variable name="pass1-results" as="document-node()">
      <xsl:apply-templates select="/" mode="pass1"/>
    </xsl:variable>

    <xsl:variable name="pass2-results" as="document-node()">
      <xsl:apply-templates select="$pass1-results" mode="pass2"/>
    </xsl:variable>

    <xsl:variable name="pass3-results" as="document-node()">
      <xsl:apply-templates select="$pass2-results" mode="pass3"/>
    </xsl:variable>

    <xsl:variable name="pass4-results" as="document-node()">
      <xsl:apply-templates select="$pass3-results" mode="pass4"/>
    </xsl:variable>

    <xsl:sequence select="$pass4-results"/>
  </xsl:template>

That solved the problem and avoided problematic template interactions, but it
made me feel defeated because I resorted to a linear way of solving the
problem.

If anyone is curious, more details about the problem are available at

https://blog.oxygenxml.com/topics/preprocessing_ditaot_project_files.html

and the XSLT file itself is at

https://blog.oxygenxml.com/topics/preprocessing_ditaot_project_files/preproce
ss_project_file.xsl

 - Chris

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.