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

Re: <xsl:apply-templates select="not('nodename')"/> ?

Subject: Re: <xsl:apply-templates select="not('nodename')"/> ?
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Tue, 27 Aug 2002 17:08:45 +0100
xsl apply templates select not
Stuart Brown wrote:
>> I would like to preferentially list some children ahead of others.
>> I'm trying to do it like this:
>> 
>> <xsl:apply-templates select="./apple"/>
>> <xsl:apply-templates select="./orange"/>
>> <xsl:apply-templates select="not(apple|orange)"/>
>> 
>> ... I want for the third line to process all other children. It's
>> not working that way though. What's the right syntax to achieve
>> this?
>
> It's probably better to use template modes for this:
>
> <xsl:apply-templates mode="doApples"/>
> <xsl:apply-templates mode="doOranges"/>
> <xsl:apply-templates mode="theRest"/>
>
> <!-- Apples mode: process apple and ignore everything else -->
> <xsl:template match="apple" mode="doApples">
>   <xsl:copy/>
> </xsl:template>
> <xsl:template match="*" mode="doApples"/>
[snip]

I wouldn't advise doing this, as each time you apply templates in a
separate mode you tell the processor to locate a template for each of
the children of the element. That's a lot more work for the processor
than selecting the set of elements that you want and processing only
those. Of course that doesn't mean you can't use modes as well, just
I'd do:

  <xsl:apply-templates select="apple" mode="doApples" />

for example.

> If you really want to do it your way, use select="not(name() =
> 'apple' or name() = 'orange')".

Nope, for two reasons. First, the select attribute on
xsl:apply-templates has to select a node set, but this expression
returns a boolean value (true or false). Second, using the name()
function isn't a good way of testing what an element is -- it doesn't
take into account the namespace of an element, instead using the
element's *prefix*, which might change from document to document.

The best method (as others have said) is:

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

Cheers,

Jeni

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


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


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.