[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] testing which files have same element/@code


Subject: Re: [xsl] testing which files have same element/@code
From: Rick Taylor <taylor@xxxxxxxx>
Date: Tue, 19 Aug 2003 10:17:30 -0600

James,

This should work. However, it might be slow if you have lots of files to parse.

<xsl:param name="codeValue" select="'124'"/>

<xsl:template match="files">
<form action="http://www.foo.com">
<select name="File-to-see">
<xsl:apply-templates select="file[count(document(@filename)/foo/bar[@code=$codeValue]) &gt; 0]"/>
</select>
<input type="hidden" name="code" value="{$codeValue}"/>
<input type="submit"/>
</form>
</xsl:template>



<xsl:template match="file"> <option name="{@name}"> <xsl:value-of select="@filename"/> </option> </xsl:template>

rick.


At 03:42 PM 7/29/03 +0100, you wrote:
Ok, I'm not sure the best way to attempt this.  Let's say I have
a file:
--------filelist.xml
<files>
<file filename="file1.xml" name="File One"/>
<file filename="file2.xml" name="File Two"/>
<file filename="file3.xml" name="File Three"/>
<file filename="file4.xml" name="File Four"/>
</files>
--------

Listing some files and a name.  And then each of these
files looks something like:

--------file1.xml
<foo>
<bar code="123"> stuff </bar>
<bar code="124"> stuff </bar>
<bar code="126"> stuff </bar>
<bar code="103"> stuff </bar>
</foo>
--------
Except that each file may have <bar> elements with
different @code attributes.

What I want to do is given a @code as an xsl:param or variable
look through each file in filelist.xml to produce a list of
those files which contain a @code that matches, outputting
something like say an html form (assuming file3.xml doesn't contain
a bar/@code='124') of something like:

--------
<form action-"http://www.foo.com">
        <select name="File-to-see">
       <option value="file1.xml">File One</option>
       <option value="file2.xml">File Two</option>
       <option value="file4.xml">File Four</option>
        </select>
        <input type="hidden" name="code" value="124"/>
        <input type="submit" />
</form>
--------

Better still, I'd like to be able to xsl:call-template this with
a parameter in a number of stylesheets as it strikes me it could
be useful if modular.

So.. any suggestions on even where to start.  I'd assume that I'd
take filelist.xml as the input file, and xsl:for-each file/@filename
use document to check if bar/@code exists, if it does then
output the option.  (No sorting needed as the order in filelist.xml
is fine.)

Is that the right way to go about it?  I thought I'd ask first this
time rather than beat my head against it for a day or two only to be
told that there is a much better way.

Thanks for any advice,
James
--
Dr James Cummings, James.Cummings@xxxxxxxxx, http://www.uea.ac.uk/~q503
Cursus Project, School of Music, University of East Anglia,
Norwich, Norfolk, NR4 7TJ, UK  Tel:(01603)593-595



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

Rick Taylor XML Developer PPDM Association


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




Current Thread
Keywords
xml