[xsl] Using a pre-processor for dynamic inputs

Subject: [xsl] Using a pre-processor for dynamic inputs
From: David Adams <dpadams@xxxxxxxxx>
Date: Sat, 11 Sep 2004 15:04:30 +1000
I've got another database-person-turning-to-XSLT question. Again, I'm 
starting with a 200K XML file that includes the names of the birds
that occur in Australia, as illustrated in the fragment below:

<Australian_Birds>
	<Species>
		<Sequence>1</Sequence>
		<Family_Name>Struthionidae</Family_Name>
		<Genus_Name>Struthio</Genus_Name>
		<Species_Name>camelus</Species_Name>
		<Common_Name>Ostrich</Common_Name>
		<Extinct>False</Extinct>
	</Species>
	<Species>
		<Sequence>2</Sequence>
		<Family_Name>Casuariidae</Family_Name>
		<Genus_Name>Casuarius</Genus_Name>
		<Species_Name>casuarius</Species_Name>
		<Common_Name>Southern Cassowary</Common_Name>
		<Extinct>False</Extinct>
	</Species>
</Australian_Birds>

What I'd like to do is to make it possible to use XSLT to produce any
number of outputs from this source file based on dynamic inputs. For
example, allowing for a search on genus where there can be a varible
number of inputs. In one case, the search might be for "Struthio" and
in another "Struthio" and "Casuarius". Based on my reading and the
kind answer to my earlier question, I now know that there are a couple
of ways to build the XSLT to perform this task _if_ the inputs are
known. But that's the problem, they're dynamic inputs. If I understand
it correctly, you can supply values through parameters which are
basically XSLT variables set from the outside world. And, again if I
understand it correctly, variables/parameters are something between
constants and variables in other languages, to my way of thinking. In
my case, the binding time sounds like it's too early.

Is there a natural solution to this situation in XSLT? Bascially what
I want is to select a series of node sets based on an input array
(array/list/vector/whatever.) The solution I came up with is to
pre-process the XSLT. The unprocessed sheet isn't valid XML as it gets
fed to a tag processor. Something like this:

	<xsl:template match="Australian_Birds">
               for (each item in an input array)
		<xsl:apply-templates
select='/Australian_Birds/Species[Genus_Name="insert array element
value here"]'/>
               end loop
	</xsl:template>

The output is then something like this:

	<xsl:template match="Australian_Birds">
		<xsl:apply-templates
select='/Australian_Birds/Species[Genus_Name="Struthio"]'/>
		<xsl:apply-templates
select='/Australian_Birds/Species[Genus_Name="Casuarius"]'/>
	</xsl:template>

If the input array had three elements, there would be three
xsl:apply-templates statements, and so on.

This obviously works, but is there a native way of accomplishing the
same task? If not, is the solution I'm using considered reasonable or
is it regarded as an abomination?

Thanks again for any help. And, again, feel free to point me to
existing discussions I've missed. I've tried searching but may be
missing what I'm looking for as I don't know the appropriate local
terminology.

-- 
---------------------------------------------
 David Adams
  dpadams@xxxxxxxxx
 Bermagui 2546 NSW
---------------------------------------------

--+------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe@xxxxxxxxxxxxxxxxxxxxxx>
--+--

Current Thread