Re: [xsl] collecting a fileset with XSLT 2.0

Subject: Re: [xsl] collecting a fileset with XSLT 2.0
From: Mark Giffin <m1879@xxxxxxxxxxxxx>
Date: Mon, 06 Feb 2012 13:47:25 -0800
Nice! Thanks again. Here's to getting rid of old hoariness.

Mark

On 2/6/2012 12:46 PM, Wendell Piez wrote:
Mark,

This is cool.

On 2/6/2012 12:50 PM, Mark Giffin wrote:
Thanks Wendell, also good to know. In this project I ran out of time and
couldn't take the time to work out how to use collection(), so I handled
it elsewise. collection() would have required a ton of refactoring on
this project. I realized I mainly needed to exclude a couple files, so I
embedded a little lookup table in the stylesheet that holds a couple
strings:

<st:exclude>
<st:file name="filename1.xml"/>
<st:file name="filename2.xml"/>
</st:exclude>

Then I made a key to parse it:

<xsl:variable name="excluded-files"
select="document('')/xsl:stylesheet/st:exclude"/>

Or you could simply do


<xsl:variable name="excluded-files" as="element(st:file)+">
<st:file name="filename1.xml"/>
<st:file name="filename2.xml"/>
  ...
</xsl:variable>

and take it from there.

(The hoary old XSLT 1.0 trick you used is no longer necessary. :-)

Then you may not need the key any more either, as

exists($excluded-files[@name=$this-file])

will then tell you what you need to know, probably as fast.

(Many things can become much simpler under 2.0.)

Cheers,
Wendell


<!-- Key to parse $excluded-files. --> <xsl:key name="excluded" match="st:file" use="@name"/>

And excluded those files by testing it with key():

<xsl:when test="exists(key('excluded', $thisfile, $excluded-files))">
<!-- do nothing -->
</xsl:when>

Maybe later I can get cooler with collection().

Current Thread