xsl-list
[Top] [All Lists]

Re: [xsl] How to cope with the complexity of an XSLT program with thousands of template rules?

2022-06-02 07:40:46
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/preprocess_project_file.xsl

 - Chris

--~----------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
EasyUnsubscribe: http://lists.mulberrytech.com/unsub/xsl-list/1167547
or by email: xsl-list-unsub(_at_)lists(_dot_)mulberrytech(_dot_)com
--~--


<Prev in Thread] Current Thread [Next in Thread>