|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Custom node-set in a variable
Leonid,
At 09:42 AM 2/17/2005, you wrote: You can do this, but it requires a little extra effort to do so in XSLT 1.0. This is because a variable declared this way is not bound to a true node-set, but rather to a result tree fragment -- which is much like a node set with the caveat that you can't query into it -- which is, unfortunately, exactly what you need to do. The XSLT 1.0 workaround to this problem takes two forms: * use an extension function such as exslt:node-set() to turn the result fragment into a node set * use the document() function to query the document where this node set appears, instead of simply using the variable as bound. Since document('') returns the stylesheet as a (parsed) document, this can be done like so: <xsl:variable name="bypass-names-RTF">
<element1 />
<element2 />
...
</xsl:variable> <xsl:variable name="bypass-names"
select="document('')/*/xsl:variable[@name='bypass-names-RTF]/*"/>So now $bypass-names is actually a node set, which you can traverse. Now as for your real question.... And what would be the good way to handle the exclusion, keeping in mind performance? Actually, not as you have it, like <xsl:variable name="bypass-names-RTF"> <element1 /> <element2 /> ... </xsl:variable> but rather something like <xsl:variable name="bypass-names-RTF"> <name>element1</name> <name>element2</name> <name>element3</name> ... </xsl:variable> This is nice because then the names you want to bypass can be collected as a set of nodes whose values, not names, can be checked against. That is, since $bypass-names (using the declaration described above) will be a set of <name> elements, the names you want to exclude is available as the *values* of the node-set $bypass-names. The equality operator "=" in XPath is very handy for the test you then need to do ... for any element in your input, when test="name() = $bypass-names" you know its name is in the set. (You might want to research the name() and local-name() functions, since it could matter which one you use, if you have namespaces in play.) This is a special application of a "lookup table", which you will find documented in the XSLT FAQ and elsewhere. Cheers, Wendell
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








