Subject: Re: Understanding named templates and their parameters
From: James Clark <jjc@xxxxxxxxxx>
Date: Sun, 25 Apr 1999 07:34:35 +0700
|
Michel Goossens wrote:
>
> <xsl:template name="listitem">
> <xsl:param-variable name="labeltext">labeltext</xsl:param-variable>
> <xsl:param-variable name="itemid">itemid</xsl:param-variable>
> <xsl:param-variable name="itemtext">itemtext</xsl:param-variable>
> <fo:list-item id="{$itemid}">
> <fo:list-item-label font-style="italic">
> $labeltext<xsl:text>:</xsl:text>
Character data in a template is copied straight through to the result;
nothing is done with it beyond normal XML parsing. $labeltext is an
expression; you want to put the string value of the expression into the
result. The way to do that is to use xsl:value-of:
<xsl:value-of select="$labeltext"/>
> </fo:list-item-label>
> <fo:list-item-body>
> <xsl:value-of select="$itemtext"/>
> </fo:list-item-body>
> </fo:list-item>
> </xsl:template>
>
> <xsl:template match='/'>
> <fo:page-sequence>
> <xsl:apply-templates/>
> </fo:page-sequence>
> </xsl:template>
>
> <xsl:template match="invitation">
> <fo:list-block>
> <xsl:call-template name="listitem">
> <xsl:param name="labeltext">To</xsl:param>
> <xsl:param name="itemid">listto</xsl:param>
> <xsl:param name="itemtext">to</xsl:param>
This defines the parameter "itemtext" to have a value that's a result
tree fragment containing a single text node with the characters "to".
Thus when you do <xsl:value-of select="$itemtext"/> you will insert the
characters "to". What you need is a parameter whose value is a node-set
containing the "to" child of the invitation. You get that with:
<xsl:param name="itemtext" expr="to"/>
You could alternatively do:
<xsl:param name="itemtext"><xsl:value-of select="to"/></xsl:param>
That would give you a parameter that was a result tree fragment
consisting of a text node whose value was the content of the "to" child
of the invitation.
James
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|