Re: [xsl] Updating XML

Subject: Re: [xsl] Updating XML
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Tue, 17 Dec 2002 17:02:28 +0000
Hi Marko,

>         <!-- apply all elments except section, simplesect, index and
>               bibliography, but also apply index and bibliography, if
>               they are followed by an element which is not index or
>               bibliography -->
>        <xsl:apply-templates select="*[(
>                    not(name() = 'section') and
>                    not(name() = 'simplesect') and
>                    not(name() = 'index') and
>                    not(name() = 'bibliography')
>                    ) or (
>                    (
>                    name() = 'index' or
>                    name() = 'bibliography'
>                    ) and
>                    following-sibling::*[
>                       not(name() = 'index') and
>                       not(name() = 'bibliography')
>                       ])]"/>

You could simplify this by using the self:: axis rather than testing
using the name() function (the self:: axis is also better because it's
namespace-aware):

  <xsl:apply-templates
    select="*[not(self::section or self::simplesect or
                  self::index or self::bibliography)] |
            (index | bibliography)
              [not(following-sibling::index or
                   following-sibling::bibliography)]" />

Alternatively, you could use a mode. Apply templates in "non-section"
mode:

  <xsl:apply-templates mode="non-section" />

and then have templates in that mode that do nothing for the section
etc. elements:

<xsl:template match="section | simplesect | index | bibliography"
              mode="non-section" />

<xsl:template match="index[not(following-sibling::index or
                               following-sibling::bibliography)] |
                     bibliography[not(following-sibling::index or
                                      following-sibling::bibliography)]">
  ...
</xsl:template>

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread