|
Subject: Re: [xsl] explicit filter From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx> Date: Mon, 14 May 2001 16:52:52 +0100 |
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 |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| [xsl] explicit filter, Torsten Curdt | Thread | [xsl] Accessing the JavaScript Math, Chris Bayes |
| [xsl] Use of variables in location , Bob Kline | Date | RE: [xsl] xmlspy and copy-of, Khan, Amir |
| Month |