tags:

views:

24

answers:

1

I have 2 pieces of code in my XSL file.

1)

<xsl:call-template name="Info">
    <xsl:with-param name="parententry" select="a:feed/a:entry/@href" />
</xsl:call-template>

2)

<xsl:template name="Info">
    <xsl:param name="parentEntry" />
        <xsl:variable name="parententryauthorname">
            <xsl:value-of select="a:author/a:name" />
        </xsl:variable>
        <xsl:variable name="info2">
            <xsl:value-of select="$parentEntry" />
        </xsl:variable>>
        <input name="info2" type="hidden" value="{$info2}" />
        <input name="parententryauthorname" type="hidden" value="{$parententryauthorname}" />
</xsl:template>

What I want to do is to assign a value to "parententry" at 1st piece of code , and then refer it at the 2nd place. When I am in the "Info" template, I want to further process the value assigned in "parententry" to get the author's name.

Right now, when I tried to print the value of $info2, and $parententryauthorname, they are both empty.

Any suggestions?

A: 

This stylesheet:

<xsl:stylesheet version="1.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
 xmlns:atom="http://www.w3.org/2005/Atom"
 exclude-result-prefixes="atom">
    <xsl:template match="/">
        <xsl:apply-templates select="*/atom:entry" mode="form"/>
    </xsl:template>
    <xsl:template match="atom:entry" mode="form">
        <input name="info2" type="hidden" 
               value="{atom:link[@rel='alternate']/@href}" />
        <input name="parententryauthorname" type="hidden" 
               value="{atom:author/atom:name}" />
    </xsl:template>
</xsl:stylesheet>

With this page's feed, output:

<input name="info2" type="hidden" value="http://stackoverflow.com/questions/3754954/how-to-refer-a-variable-within-xsl-from-one-function-to-another-function" />
<input name="parententryauthorname" type="hidden" value="Java Doe" />
<input name="info2" type="hidden" value="http://stackoverflow.com/questions/3754954/how-to-refer-a-variable-within-xsl-from-one-function-to-another-function/3755184#3755184" />
<input name="parententryauthorname" type="hidden" value="Alejandro" />

Note: When processing nodes in differents ways, modes are the right tool.

Edit: Update the output with the new feed. Just for fun!

Alejandro