Using a variable in a output element

Here should go questions about transforming XML with XSLT and FOP.
sderrick
Posts: 264
Joined: Sat Jul 10, 2010 4:03 pm

Using a variable in a output element

Post by sderrick »

I have a simple function to output a <span/> tag . One of the <span/> attributes uses a param of the template.

The param is id, referenced in the url attribute as $id, since its in a string "taxonomy/mbe_persons1.html?refid=($id)" is is hidden and doesn't evaluate as a variable.

If I try to use the <xsl:value-of select="$id"/> in place of $id, the parser complains about using the <> characters in the url attribute.

Code: Select all

<xsl:template name="personPageLink">
    <xsl:param name="id"/>
    <p><span class="addDocTab" url="taxonomy/mbe_persons1.html?refid=($id)" title="Click to see more letters" rel="People References">See more letters.</span></p>
  </xsl:template>
anybody know of a way around this?

thanks, Scott
Radu
Posts: 9059
Joined: Fri Jul 09, 2004 5:18 pm

Re: Using a variable in a output element

Post by Radu »

Hi Scott,
You can probably do something like:

Code: Select all

<span class="addDocTab" url="taxonomy/mbe_persons1.html?refid=({$id})" title="Click to see more letters" rel="People References">See more letters.</span>
Using "{" and "}" in attribute values allows you to add xpath expressions there.
Or you can re-write the entire span in XSLT like:

Code: Select all

        <xsl:element name="span">
            <xsl:attribute name="class">addDocTab</xsl:attribute>
            <xsl:attribute name="url" select="concat('taxonomy/mbe_persons1.html?refid=(', $id, ')')"/>
            <xsl:attribute name="title">Click to see more letters</xsl:attribute>
            <xsl:attribute name="rel">People References</xsl:attribute>
            See more letters.
        </xsl:element>
Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
sderrick
Posts: 264
Joined: Sat Jul 10, 2010 4:03 pm

Re: Using a variable in a output element

Post by sderrick »

Radu you are a life saver! I've used this a long time ago and completely forgot it!

thanks again,
Scott
Post Reply