1。position() mode 2
例:Coloring alternate rows
例: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>
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: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 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>
<xsl:param name="N"/>
<xsl:value-of select="$N div 2"/>
</xsl:template>

文章来源:http://spaces.msn.com/members/jewer91/Blog/cns!1p6udCMYMrSYD0M1VOX6N3VQ!126.entry
浙公网安备 33010602011771号