您的位置:首页 > 其它

[导入]xslt例子(Coloring alternate rows和两个Template例子):

2005-10-13 13:47 309 查看
1。position() mode 2
例:Coloring alternate rows
<TABLE border="1" width="25%">
<xsl:for-each select="/FitnessCenter/Member">
<TR>
<xsl:if test="position() mod 2 = 0">
<xsl:attribute name="bgcolor">yellow</xsl:attribute>
</xsl:if>
<TD><xsl:value-of select="Name"/></TD>
</TR>
</xsl:for-each>
</TABLE>

2。Dument(url) :指向外部另一个Xml文档

<xsl:variable name="fitnessCenter2"
select="document('file://localhost/xml-course/.../FitnessCenter2.xml')"/>
<xsl:for-each select="$fitnessCenter2/FitnessCenter/Member">
3。<xsl:call-template
例:使用带参数(param)的模板(template)
<xsl:template match="/">
<HTML>
<HEAD>
<TITLE>Fitness Center</TITLE>
</HEAD>
<BODY>
<xsl:call-template name="displayNameWithFont">
<xsl:with-param name="fontFace" select="'Impact'"/>
<xsl:with-param name="name"
select="/FitnessCenter/Member[1]/Name"/>
</xsl:call-template>
<BR/>
...
</BODY>
</HTML>
</xsl:template>
<xsl:template name="displayNameWithFont">
<xsl:param name="fontFace" select="'Braggadocio'"/> <!-- default font -->
<xsl:param name="name"/>
<FONT face="{$fontFace}">
<xsl:value-of select="$name"/>
</FONT>
</xsl:template>
使用带参数的模板例二:
<xsl:template match="/">
<HTML>
<HEAD>
<TITLE>Fitness Center</TITLE>
</HEAD>
<BODY>
16 / 2 =
<xsl:variable name="result">
<xsl:call-template name="NumDiv2">
<xsl:with-param name="N" select="16"/>
</xsl:call-template>
</xsl:variable>
<xsl:value-of select="$result"/>
</BODY>
</HTML>
</xsl:template>
<xsl:template name="NumDiv2">
<xsl:param name="N"/>
<xsl:value-of select="$N div 2"/>
</xsl:template>




文章来源:http://spaces.msn.com/members/jewer91/Blog/cns!1p6udCMYMrSYD0M1VOX6N3VQ!126.entry
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: