2010-09-20 36 views
-1

我在我的XSL文件中有两段代码。如何将XSL中的变量从一个函数引用到另一个函数?

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> 

我想要做的是在第一个的代码值分配给“parententry”,然后在第2位是指它。当我在“信息”模板中时,我想进一步处理在“parententry”中分配的值以获取作者的姓名。

现在,当我试图打印$ info2和$ parententryauthorname的值时,它们都是空的。

有什么建议吗?

+0

1的 \t的 dojomedojo 2010-09-20 19:50:13

+0

2.的 \t \t的 \t的 \t \t \t \t的 \t \t \t的 \t \t> \t \t <输入名称= “INFO2” 类型= “隐藏” 值= “{$ INFO2}”/> \t \t dojomedojo 2010-09-20 19:51:18

回答

0

这个样式表:

<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> 

有了这个页面的饲料,输出:

<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" /> 

注意:在型动物方式处理节点,模式是正确的工具。

编辑:使用新提要更新输出。只是为了好玩!

相关问题