以文本方式查看主题

-  中文XML论坛 - 专业的XML技术讨论区  (http://bbs.xml.org.cn/index.asp)
--  『 XSL/XSLT/XSL-FO/CSS 』  (http://bbs.xml.org.cn/list.asp?boardid=8)
----  求助:param的问题  (http://bbs.xml.org.cn/dispbbs.asp?boardid=8&rootid=&id=40099)


--  作者:跳绳儿
--  发布时间:11/16/2006 2:31:00 PM

--  求助:param的问题
刚开始学,老板要我写段xsl,我现在遇到个问题,请大虾们帮个手

就写个框架吧,太长了不好看:

<xsl:template name="D">
<xsl:choose>
   <xsl:when test=”……“>code1
   </xsl:when>
<xsl:otherwise>code2
</xsl:otherwise>
</xsl:template>

就这么个结构,param的定义和with-param不是只能在template里面么?choose里面不能定义。

我想在when和otherwise里面分别定义两个param,暂且叫param1,param2,code1用完param1后改变param1的值,code2用完param2后改变param2的值,这样call-template的时候每次要么param1变,要么param2变。怎么定义呢?


--  作者:Qr
--  发布时间:11/16/2006 9:55:00 PM

--  
<xsl:with-param> 元素
--------------------------------------------------------------------------------
定义与用法
<xsl:with-param>元素向模板传递的参数的值。
说明:<xsl:with-param>元素的name 属性的值必须与一个<xsl:param>元素的name 相匹配(否则<xsl:with-param>元素将被忽略)。
说明:<xsl:with-param>元素在<xsl:apply-templates>和<xsl:call-template>之内使用。


相比而言,<xsl:param>就没有太大限制。
=====================

示例:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="text"/>
<xsl:template match="/">
<xsl:call-template name="print">
<xsl:with-param name="A">11</xsl:with-param>
<xsl:with-param name="B">33</xsl:with-param>
</xsl:call-template>
<xsl:call-template name="print">
<xsl:with-param name="A">55</xsl:with-param>
</xsl:call-template>
</xsl:template>
<xsl:template name="print">
<xsl:param name="A"/>
<xsl:param name="B">111</xsl:param>
<xsl:text>
</xsl:text>
<xsl:value-of select="$A"/>
<xsl:text> + </xsl:text>
<xsl:value-of select="$B"/>
<xsl:text> = </xsl:text>
<xsl:value-of select="$A+$B"/>
</xsl:template>
</xsl:stylesheet>
这个例子的输出结果为
11 + 33 = 44 55 + 111 = 166


--  作者:跳绳儿
--  发布时间:11/18/2006 4:15:00 PM

--  
谢谢楼上的,我知道用法,我现在的问题是我希望递归调用模版的时候,分情况改变不同的参数,但是xsl:call-template 可能不包含 xsl:choose,改怎么办呢?

<xsl:call-template name="DrawEllipse">
  <xsl:choose>
   <xsl:when test="……">
<xsl:with-param name="zindex1" select="$zindex1+1"/>
</xsl:when>
<xsl:otherwise>
<xsl:with-param name="zindex2" select="$zindex2 - 1"/>
</xsl:otherwise>
</xsl:choose>
</xsl:call-template>
这当然是不合语法的,我怎么才能实现这个意思呢


W 3 C h i n a ( since 2003 ) 旗 下 站 点
苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
78.125ms