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

Re: explicit filter

Subject: Re: explicit filter
From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx>
Date: Mon, 14 May 2001 16:52:52 +0100
xsl copy filter
Hi Torsten,

> Unfortunately I need to filter the node set on something much more
> comlex. So I thouhght I could traverse the nodes, test them and
> return the good ones. Unfortunately this doesn't seem to work... So
> I tried a simple node set copy first. But this didn't work either:

When you copy nodes, you're creating nodes in the result tree or (if
you do it in a variable) in a result tree fragment.  If you do:

>     <xsl:variable name="filtered_elements">
>       <xsl:for-each select="$elements">
>         <xsl:copy><xsl:copy-of select="@*"/></xsl:copy>
>       </xsl:for-each>
>     </xsl:variable>

you get a result tree fragment that has shallow-ish copies of the
filtered elements (i.e. they have attributes but don't have content).

[Actually I think you probably want deep copies, use xsl:copy-of
instead:

  <xsl:variable name="filtered_elements_rtf">
     <xsl:for-each select="$elements">
        <xsl:copy-of select="." />
     </xsl:for-each>
  </xsl:variable>]

To access those nodes as a node set, you have to turn the result tree
fragment into a node set, using exsl:node-set() if your processor
supports it or its proprietary node-set() function if it doesn't.

   <xsl:variable name="filtered_elements"
                 select="exsl:node-set($filtered_elements_rtf)/*" />

This compromises the portability of your stylesheet somewhat; you
might want to filter the elements lower down in the stylesheet, where
you're actually thinking about doing something with them instead, but
it's hard to tell from your description.

[General point, and another plug - XPaths can be pretty complex, but
they do sometimes fall down, particularly when there are conditional
strings or numbers involved.  If your processor supports func:function
(see http://www.exslt.org/func/elements/function) then you could
create a boolean function to test the nodes and filter them.]

I hope that helps,

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.