Re: [xsl] problem with Passing Parameters to Templates

Subject: Re: [xsl] problem with Passing Parameters to Templates
From: David Carlisle <davidc@xxxxxxxxx>
Date: Mon, 22 Jan 2001 15:25:33 GMT
> Did I do something wrong?


Firstly the simple answer to your question:

> What I really want to do is to output the value of element codec(

appears to be

<xsl:value-of select=".//codec"/>

in which case you don't have any params to worry about, but
to see what's wrong with your code node that you have defined $node 
to be a string. It is always the empty string or 'codec'.

          <xsl:if test=".//*[$node]">

this is using $node in a predicate so the string will be coerced to a
boolean. If it is empty (ie if the named template is called without an
explicit parameter) then it will have boolean value false


selects all elements for which false is true.

.// searches for all descendents of the current node for which the above
is true.

As false is never true this will return the empty nosde set.

This node set is used in an if test so will be coerced to boolean as
false. So in this case the value-of clause will be skipped.

If $node is codec then [$codec] is the same as [true()] so
will be true if the current node has any element children and will be
false otherwise.

If it is true then the value-of will be evaluated. which will return the
value of the first codec descendent.

As you see the xsl:if isn't doing anything useful in either case
you could just miss it out and say
       <xsl:value-of select=".//*[name()=$node]"/>

If there are no elements of that name, you don't need to test with
xsl:if, you just get nothing returned.


 XSL-List info and archive:

Current Thread