相关疑难解决方法(0)

XSL:在模板之间传递变量

是否可以将变量从一个父模板传递给其子元素?

<xsl:template match="structure">
  <xsl:variable name="var"><xsl:value-of select="@path" /></xsl:variable>
  <xsl:apply-templates select="folders">
    <xsl:with-param name="var1" select="'{var}'"/>
  </xsl:apply-templates>
</xsl:template> 
Run Code Online (Sandbox Code Playgroud)

此模板将匹配:

<xsl:template match="folder">
  <xsl:param name="var1"/>
  <xsl:value-of select="$var1"/>
</xsl:template>
Run Code Online (Sandbox Code Playgroud)

你看我想在匹配的模板中使用var作为var1.

我怎样才能做到这一点?

编辑:结构是这样的:

<structure path="C:\xampplite\htdocs\xampp">
  <folders>
    <folder name="img">
      <date>01/28/10 21:59:00</date>
      <size>37.4 KB</size>
    </folder>
 </folders>
</structure>
Run Code Online (Sandbox Code Playgroud)

EDIT2:

<xsl:template match="folder">
<xsl:variable name="var1"><xsl:value-of select="../../@path"/></xsl:variable>
<xsl:variable name="var2"><xsl:value-of select="@name" /></xsl:variable>
<xsl:variable name="var3"><xsl:value-of select="$var1"/>\<xsl:copy-of select="$var2"/>    </xsl:variable>
 <th colspan="2" align="left"  bgcolor="#FF5500"><a onclick="foo('{$var3}')"><xsl:value-of select="$var3"/></a></th>
Run Code Online (Sandbox Code Playgroud)

在jscript函数中,字符串没有反斜杠.有谁知道为什么?

C:xampplitehtdocsxamppimg

xml xslt

13
推荐指数
3
解决办法
6万
查看次数

标签 统计

xml ×1

xslt ×1