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

Re: [xsl] top level params and xsl:attribute magic?


Subject: Re: [xsl] top level params and xsl:attribute magic?
From: Dimitre Novatchev <dnovatchev@xxxxxxxxx>
Date: Fri, 17 Jan 2003 23:34:56 -0800 (PST)

Another way to completely avoid both having to use xx:evaluate() or an
external API:

Instead of using the XPath expression to a node as its unique id, use
the pair: 

(count(ancestor::node()), count(preceding::node()) )

This means that you will be passing as parameter a pair of numbers,
e.g.:

3,15

Then you can get these two numbers in two variables and find your node
with the following XPath expression:

//node()[count(ancestor::node()) = $v1 
       and 
         count(preceding::node()) = $v2
         ]

Or you could define a key, so that the node(s) will be found faster.



=====
Cheers,

Dimitre Novatchev.
http://fxsl.sourceforge.net/ -- the home of FXSL



--- Dimitre Novatchev <dnovatchev@xxxxxxxxx> wrote:
> First, I would stroongly recommend *not* to use any xx:evaluate
> function.
> 
> As anyway you are passing the XPath expression through a global
> xsl:param (which is done outside of XSLT processing, using some kind
> of
> API), it would be much better to set the value of the "select"
> attribute of this particular xsl:param (again through the API (most
> probably XML DOM)) to the string/XPath-expression.
> 
> This is both simple and efficient, it completely eliminates your
> current problem.
> 
> > Compare to this (which doesn't work): (2)
> >    <xsl:param name="StartNode">
> >          <xsl:attribute name="select">
> >            <xsl:value-of select="dyn:evaluate($StartPointStr)"/>
> >          </xsl:attribute>
> >    </xsl:param>
> > 
> > (1) works and (2) doesn't work.
> 
> In the snippet above you're specifying the value of the "select"
> attribute to the *string* value of the *first* node in the node-set
> returned by dyn:eveluate().
> 
> This, of course, is completely different to setting the "select"
> attribute to the node-set.
> 
> Once again, the best way in your situation is to forget about
> extension
> functions and to set the "select" attribute totally from outside and
> just before the start of the transformation.
> 
> This is the way the XPath Visualiser (both for IE and Mozilla) works
> --
> do have a look at its code.
> 
> 
> =====
> Cheers,
> 
> Dimitre Novatchev.
> http://fxsl.sourceforge.net/ -- the home of FXSL
> 
> 
> 
> "S Woodside" <sbwoodside@xxxxxxxxx> wrote in message
> news:F2CC80BE-2AA0-11D7-8385-000393414368@xxxxxxxxxxxx
> > I'm beginning to think that XSLT is a bit like magic. If you think
> the 
> > right way, and use the right magic incantation, it works like a
> charm. 
> > If you don't, no cigar.
> > 
> > I have this top-level param to grab a param from http:
> >    <xsl:param name="StartPointStr">.</xsl:param>
> > 
> > The param StartPointStr is an Xpath string. Next I have this (which
> 
> > works) (1)
> >    <xsl:param name="StartNode"
> select="dyn:evaluate($StartPointStr)"/>
> > 
> > Compare to this (which doesn't work): (2)
> >    <xsl:param name="StartNode">
> >          <xsl:attribute name="select">
> >            <xsl:value-of select="dyn:evaluate($StartPointStr)"/>
> >          </xsl:attribute>
> >    </xsl:param>
> > 
> > (1) works and (2) doesn't work. With two, I get nothing, empty node
> 
> > set. They should be equivalent!
> > 
> > OK, wait, I see in the spec "The xsl:attribute element can be used
> to
> 
> > add attributes to result elements" ... so this must be an illegal
> use
> 
> > of xsl:attribute. But LibXSLT doesn't complain ... maybe this is
> just
> a 
> > case of inadequate error detection and reporting the in the 
> > implementation (I used to see that very often in C++ compilers...)
> > 
> > simon
> > 
> > ---
> > www.simonwoodside.com
> > 
> > 
> >  XSL-List info and archive: 
> http://www.mulberrytech.com/xsl/xsl-list
> > 
> 
> __________________________________________________
> Do you Yahoo!?
> Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
> http://mailplus.yahoo.com
> 


__________________________________________________
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com

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



Current Thread
Keywords