XSLT(5) param and variable

param and variable are immutable. They can be global or local

<xsl:param>

<xsl:param  name="name"  select="expression" as="dataType" >

  <!-- Content:template -->

</xsl:param>


Then you can use $name to represent the selected expression. You have to explicitly supple the param in the command line

example:

java -cp saxon9ee.jar net.sf.saxon.Transform -t -s:HelloWorld.xml   -xsl:HelloWorld.xsl -o:c:\temp.html



<xsl:variable>

variable can be global if it is defined as a child of xsl:stylesheet or it can be local if defined inside template

<xsl:variable  name="name"  select="expression" as="dataType">

  <!-- Content:template -->

</xsl:variable>

example:
<xsl:variable name="color" select="'red'" />
<xsl:variable name="dueDate" select="'2003-12-08'" as="xs:date" />

Occurrence indicator

Any of the preceding sequence types can be followed by an occurrence indicator.  These indicators are the same as Those in DTDs
? - optional
* - zero or more
+ - one or more

<xsl:variable name="programs" select="Program" as = "element()+" />


Constructing Sequence containing atomic values

<xsl:variable name="seq" as="xs:integer *">
    <xsl:for-each select="1 to 5">>
       <xsl:sequence select=". * ."/>
    </xsl:for-each/>    
</xsl:variable>

This produces (1, 4, 9, 16, 25)



<xsl:with-param>

The <xsl:with-param> element defines the value of a parameter to be passed into a template.

The template that needs a param elementToDump:
<xsl:template name="dumpDebugData">
    <xsl:param name="elementToDump" />
    <xsl:for-each select="$elementToDump/@*">
      <xsl:text>&#10;</xsl:text>    <!-- newline char -->
      <xsl:value-of select="name()" /> : <xsl:value-of select="." />
    </xsl:for-each>
  </xsl:template>

Use a <xsl:with-param> to pass the parameter:
<xsl:call-template name="dumpDebugData">
  <xsl:with-param name="elementToDump" select="some/xpath" />
</xsl:call-template>


Tunneling Param

A parameter passed to a template may be defined as a tunnel parameter. Tunnel parameters have the property that they are automatically passed on by the called template to any further templates that it calls, and so on recursively.] Tunnel parameters thus allow values to be set that are accessible during an entire phase of stylesheet processing, without the need for each template that is used during that phase to be aware of the parameter.

Tunnel parameters are automatically passed through templates. To use them, the tunnel attribute on <xsl:param> and <xsl:with-param> is given the value 'yes'.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值