您的位置:首页 > 移动开发

XSL基础: call-template,apply-templates,xsl:param,with-param,number format 用法

2011-04-10 12:23 441 查看
最后结果:



XML

<?xml version='1.0'?>
<?xml-stylesheet type="text/xsl" href="C8.xslt"?>
<lists>
	<ol>
		<li>the</li>
		<li>cat</li>
		<ol>
			<li>sat</li>
			<li>on</li>
			<li>the</li>
		</ol>
		<li>mat</li>
	</ol>
</lists>


XSL

<?xml version='1.0'?>
<?xml-stylesheet type="text/xsl" href="paramelem.xsl"?>
<xsl:stylesheet version="1.0"
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      xmlns:fo="http://www.w3.org/1999/XSL/Format">
    <!--匹配XML Document中的 ol/li mark-->
	<xsl:template match="ol/li">
		<br/>
		<!--Invoke template-->
		<xsl:call-template name="number-block">
			
		</xsl:call-template>
	</xsl:template>

	<xsl:template match="ol//ol/li">
		<br/>  
	<xsl:call-template name="number-block">
		<!--Pass param to template-->
			<xsl:with-param name="format">a.</xsl:with-param>
		</xsl:call-template>
	</xsl:template>
	
	<!--Declare template named number-block-->
	<xsl:template name="number-block">
		<!--Declare a para named format -->
		<xsl:param name="format">1. </xsl:param>
		<fo:block>
			<xsl:number format ="{$format}"/>
			<!--Apply template-->
			<xsl:apply-templates></xsl:apply-templates>
		</fo:block>
	</xsl:template>
</xsl:stylesheet>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: