RE: [xsl] Using a pre-processor for dynamic inputs

Subject: RE: [xsl] Using a pre-processor for dynamic inputs
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Fri, 24 Sep 2004 08:37:42 +0100
As I think you noted in a subsequent post, your problem is that you haven't
parsed the secondary document, so the value is a string rather than being a
node at the root of a tree.

In Saxon there are about four different ways you can do this:

1. from the command line you can specify a parameter as +param=filename.
With this syntax, the specified file will be read and parsed as XML and the
root node of the XML tree will be passed as the parameter.

2. from the Java API, you can invoke a static method on the XPathEvaluator
class to parse a Source object and return the root of the resulting tree,
you can then pass this root node to the JAXP setParameter() method.

3. you can pass a URI (as a string) as the parameter value, and then parse
the file at that URI using a call on the document() function.

4. you can pass a string containing the lexical XML as the parameter value,
and then parse this XML using the saxon:parse() extension function.

Michael Kay
http://www.saxonica.com/


> -----Original Message-----
> From: David Adams [mailto:dpadams@xxxxxxxxx] 
> Sent: 23 September 2004 22:51
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: Re: [xsl] Using a pre-processor for dynamic inputs
> 
> On Sat, 11 Sep 2004 10:21:38 +0100, Michael Kay <mhk@xxxxxxxxx> wrote:
> > There are three approaches to this problem [readining 
> dynamic inputs], all of which are quite
> > respectable and widely used.
> > 
> > (a) if the inputs are fairly predictable in structure, you 
> can write your
> > stylesheet to interpret the inputs. For example, you might supply a
> > parameter to the stylesheet of the form:
> > 
> > <conditions>
> >   <condition>
> >     <attribute>name</attribute>
> >     <value>robin</value>
> >   </condition>
> >   <condition>
> >     <attribute>size</attribute>
> >     <value>small</value>
> >   </condition>
> > </conditions>
> > 
> > and then write logic in your stylesheet to select all the 
> birds that satisfy
> > all the conditions.
> 
> I'd like to take this approach but am completely stumped at how to
> process the input. How is it possible to use subelement values as
> dynamic inputs in match/select statements? I keep reading it is
> impossible. In my case, the input could looke like this:
> 
> <genera>
>   <genus>Dromaius</genus>
>   <genus>Coturnix</genus>
>   <genus>Philemon</genus>
>  </genera>
> 
> > (b) you can generate or modify the stylesheet each time it 
> is used, to
> > incorporate the specific conditions
> Yes, pre-processing works great.
> 
> > > (c) you can use an extension xx:evaluate(), available in many XSLT
> > processors, to intpret an XPath expression that's 
> constructed dynamically.
> In my case, I'm using an environment that embeds Xalan C++ 1.6 and
> don't have access to evaluate.
> 
> Many thanks in advance for suggestions. I'm getting the felling I'm
> suffering from thinking in the wrong language. Still, it's hard to
> believe that reading dynamic inputs would be an incredibly common task
> in XSLT. It also seems that supplying XML structures as inputs should
> be quite natural. Perhaps I'm missing some fundamental concept here.
> Perhaps the problem is that I'm not looking at the stylesheet aspect
> of XSLT. I'm only interested in the transformational aspect and the
> native querying abilities.

Current Thread