XSLT <xsl:with-param> 元素

定義和用法
<xsl:with-param> 元素定義了傳遞給範本的參數的值。
注意:<xsl:with-param> 元素的 name 屬性的值必須與 <xsl:param> 元素中的 name 相匹配,否則將忽略 <xsl:with-param> 元素。
注意:<xsl:apply-templates> 和 <xsl:call-template> 中均允許使用 <xsl:with-param> 元素。
提示:您可以通過 <xsl:with-param> 元素的內容或通過 select 屬性,來為參數賦值!
語法
<xsl:with-param
name="name"
select="expression">
<!-- Content:template -->
</xsl:with-param>
name="name"
select="expression">
<!-- Content:template -->
</xsl:with-param>
屬性
屬性 | 值 | 描述 |
---|---|---|
name | name | 必需。規定參數的名稱。 |
select | expression | 可選。定義參數的值的 XPath 運算式。 |
實例 1
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:variable name="xx">
<html>
<body>
<xsl:call-template name="show_title">
<xsl:with-param name="title" />
</xsl:call-template>
</body>
</html>
</xsl:variable>
<xsl:template name="show_title" match="/">
<xsl:param name="title" />
<xsl:for-each select="catalog/cd">
<p>Title: <xsl:value-of select="$title" /></p>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:variable name="xx">
<html>
<body>
<xsl:call-template name="show_title">
<xsl:with-param name="title" />
</xsl:call-template>
</body>
</html>
</xsl:variable>
<xsl:template name="show_title" match="/">
<xsl:param name="title" />
<xsl:for-each select="catalog/cd">
<p>Title: <xsl:value-of select="$title" /></p>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
