定义模板<xsl:template>
语法:
<xsl:template match="node-context" language="language-name">
<?xml version="1.0" encoding="GB2312"?>
<?xml:stylesheet type="text/xsl" href="resume_template.xsl"?>
<resume>
<name>禹希初</name>
<sex>男</sex>
<birthday>1977.5</birthday>
<skill>数据库设计与维护</skill>
<skill>WEB开发</skill>
</resume>
resume_template.xsl
<?xml version="1.0" encoding="GB2312"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">
<!--根模板-->
<xsl:template match="/">
<HTML><HEAD><TITLE>个人简历</TITLE></HEAD>
<BODY>
<xsl:apply-templates select="resume"/>
</BODY>
</HTML>
</xsl:template>
<!--简历模板-->
<xsl:template match="resume">
<TABLE border="1" cellspacing="0">
<CAPTION>个人简历(
<xsl:eval>formatIndex(childNumber(this),"I")</xsl:eval>
)</CAPTION>
<xsl:apply-templates select="name"/>
<xsl:apply-templates select="sex"/>
<xsl:apply-templates select="birthday"/>
<TR/>
<TD>技能</TD><TD COLSPAN="5">
<TABLE cellspacing="0">
<xsl:apply-templates select="skill"/>
</TABLE>
</TD>
</TABLE>
<BR/>
</xsl:template>
<!--姓名模板-->
<xsl:template match="name"><TD>姓名</TD>
<TD><xsl:value-of/></TD>
</xsl:template>
<!--性别模板-->
<xsl:template match="sex"><TD>性别</TD>
<TD><xsl:value-of/></TD>
</xsl:template>
<!--生日模板-->
<xsl:template match="birthday"><TD>生日</TD>
<TD><xsl:value-of/></TD>
</xsl:template>
<!--技能模板-->
<xsl:template match="skill">
<TR><TD><xsl:value-of/></TD></TR>
</xsl:template>
</xsl:stylesheet>
语法:
<xsl:template match="node-context" language="language-name">
属性:
match ── 确定什么样的情况下执行此模板。作为一种简化的说明,在此处使用标记的名字;其中最上层模板必须将match设为"/"。
language ── 确定在此模板中执行什么脚本语言,其取值与HTML中的SCRIPT标记的LANGUAGE属性的取值相同,缺省值是Jscript。
<xsl:template>用match属性从XML选取满足条件的节点,征对这些特定的节点形成一个特定输出形式的模板。
调用模板(块):<xsl:apply-templates>
语法:
<xsl:apply-templates select="pattern" order-by="sort-criteria-list">
属性:
select ── 确定在此上下文环境中应执行什么模板,即选取用< xsl:template >标记建立的模板(块)。
order-by ── 以分号(;)分隔的排序标准,通常是子标记的序列。
示例:
resume.xml
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
resume_template.xsl
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)