Re: [xsl] problem with Passing Parameters to Templates

Subject: Re: [xsl] problem with Passing Parameters to Templates
From: "helen li" <helen_p_li@xxxxxxxxxxx>
Date: Mon, 22 Jan 2001 11:05:26 -0500
Thanks, David.

OK, my question simply is: Can I output the value of a element which is passed thru parameter ( in my case the element is 'codec' and its value is 1234 )? I understand that I can do something simply like <xsl:value-of select="codec">. But I would like to do it with named template so that I can call the template for other elements.

in XML file, there are two lines like

And the xsl file will be something like:

    <xsl:call-template name="opt_template">
        <xsl:with-param name="node"  select="'codec'"/>

    <xsl:call-template name="opt_template">
        <xsl:with-param name="node"  select="'desc'"/>

    <xsl:template name="opt_template">
       <xsl:param name="node"></xsl:param>

=======what should be in here to output the value of element codec or desc????


Is it doable?



From: David Carlisle <davidc@xxxxxxxxx>
Reply-To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: Re: [xsl] problem with Passing Parameters to Templates
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:

_________________________________________________________________________ Get Your Private, Free E-mail from MSN Hotmail at

XSL-List info and archive:

Current Thread