Re: [xsl] xsl:apply-templates to all but...

Subject: Re: [xsl] xsl:apply-templates to all but...
From: Evan Lenz <evan@xxxxxxxxxxxx>
Date: Fri, 17 Feb 2006 09:51:44 -0800
Hi Bob,

I'm not sure if this is what you had in mind, but I often find myself restricting the node-set in the XPath expression.

<xsl:apply-templates select="y"/>
<xsl:apply-templates select="*[not(self::y)]"/>

It still requires you to enumerate the elements you know about a second time, but at least it keeps the redundancy in one place.


Bob DuCharme wrote:
xsl:apply-templates to all but...

I was curious about opinions on a processing trick I've been doing lately.
The issue: if element w has content model (x,y,z) and I want to output its
contents in (y,z,x) order, I could do this:

  <xsl:template match="w">
    <xsl:apply-templates select"y"/>
    <xsl:apply-templates select"z"/>
    <xsl:apply-templates select"x"/>

But if something later gets added to that content model, this template
rule will ignore it. If @select could take a regular expression more
complex than * or ns:*, that would be cool, but that's not an option. So
here's what I've done:

  <xsl:template match="w">
    <xsl:apply-templates select"y" mode="output"/>
    <xsl:apply-templates select"*"/>

  <xsl:template match="y" mode="output">
    <!-- process normally -->

<xsl:template match="y"/>

x and z get processed normally. (In real life, this was with larger, more
complex content models and template rules.)

Has anyone else done this? Or something similar, and if different, how so?


Bob DuCharme

Current Thread