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

Re: When to use conditional constructions?

Subject: Re: When to use conditional constructions?
From: "Abel Braaksma (Exselt)" <abel@xxxxxxxxxx>
Date: Mon, 31 Mar 2014 19:33:42 +0200
Re:  When to use conditional constructions?
On 31-3-2014 18:32, Graydon wrote:
> <xsl:template
> match="section[heading][body/table][body/para[following-sibling:table]][not(body/para[preceding-sibling:table])]">....</xsl:template>
>
> <xsl:template
> match="section[heading][body/table][body/para[following-sibling:table]][body/para[preceding-sibling:table]]">....</xsl:template>
>
> <xsl:template
> match="section[heading][body/table][not(body/para)]]">....</xsl:template>

Just a suggestion, but wouldn't this become more readable if you split
it using templates? Something like the following (not tested):

<xsl:template match="section[heading][body/table]">
    <!-- sections with tables -->
    <xsl:apply-templates
select="self::section[body/para[following-sibling::table]]"
mode="normal-section" />
    <xsl:apply-templates select="self::section[not(body/para)]"
mode="no-better-idea" />
</xsl:template>

<xsl:template match="section" mode="no-better-idea">
    ... do something ...
</xsl:template>

<xsl:template match="section[not(body/para[preceding-sibling::table])]"
mode="normal-section">
    <!-- stuff with paras and tables, but no table before para -->
</xsl:template>

<xsl:template match="section[body/para[preceding-sibling::table]]"
mode="normal-section">
    <!-- stuff with paras and tables, tables before paras -->
</xsl:template>

Not sure this effectively makes it easier for programmers or other
readers of your code, but it removes the redundant selections.

Alternatively, see my other mail for how to use function items to
achieve something similar, or to use functions, as others have already
shown. The (slight) advantage of function items is that it gives less
overhead in writing them, but conversely, when they become larger, they
tend to become less readable.

Cheers,

Abel Braaksma
Exselt XSLT 3.0 processor
http://exselt.net

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.