Subject: Re: [xsl] problem with Passing Parameters to Templates From: "helen li" <helen_p_li@xxxxxxxxxxx> Date: Mon, 22 Jan 2001 11:29:54 -0500 |
From: "helen li" <helen_p_li@xxxxxxxxxxx> Reply-To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx Subject: Re: [xsl] problem with Passing Parameters to Templates 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 <codec>1234</codec> <desc>5678</desc>
And the xsl file will be something like:
<xsl:call-template name="opt_template"> <xsl:with-param name="node" select="'codec'"/> </xsl:call-template>
<xsl:call-template name="opt_template"> <xsl:with-param name="node" select="'desc'"/> </xsl:call-template>
<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????
</xsl:template>
Is it doable?
Thanks,
Helen
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?
yes:-)
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
*[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 .//*[$codec] 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.
David
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
_________________________________________________________________________ Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com.
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
_________________________________________________________________________ Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com.
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] problem with Passing Para, David Carlisle | Thread | Re: [xsl] problem with Passing Para, helen li |
Re: [xsl] problem with Passing Para, David Carlisle | Date | Re: [xsl] problem with Passing Para, David Carlisle |
Month |