StudyNote--II DML--XML HTML CSS XPath XSLT
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xsi="http://www.w3.org/2001/XSLSchema-instance">
<xsl:output method="html"/>
<xsl:template match="Dictionary">
<html>
<head>
<link rel="stylesheet" href="dictionary.css" type="text/css"/>
<!--在html文件中加入link标签,利用link标签调用外部CSS样式文件,还可以利用<div>在html内部定义样式,或者利用<style>标签在头部定义调用,或者可以利用@import外部调用-->
<title>Bilingual Lexion <xsl:value-of select="/Dictionary/from"/>--<xsl:value-of select="Dictionary/to"/></title>
</head>
<body>
<h1>Browse by letter</h1>
<table border="0" id="table1">
<!--可以在定义table标签的时候为其加上id号,类似于table的名字,用以区分不同的table,以便于CSS样式表中对于不同的table定义样式-->
<tr>
<xsl:for-each select="/Dictionary/translation">
<xsl:sort select="@initial" data-type="number"/>
<xsl:if test="generate-id(.)=generate-id(../translation[@initial=current()/@initial])">
<!--利用generate-id()函数返回唯一节点标识指定节点的字符串值,可以利用这个等式得到重复节点的名字-->
<td>
<p><a href="{concat('#',@initial)}">
<!--文件内跳转函数的前部分,原始href="#jump"缺点是无法重复定义链接点,利用concat连接字符串,href={concat('#',string)}可以重复循环定义链接点,每次只要保证string不同即可。也可以利用href="#{generate-id()}",完成相同的功能。但是如果一个链接点对应多个链接目的点,只会跳转到最近的那个目的点-->
<xsl:value-of select="@initial"/></a></p>
</td>
</xsl:if>
</xsl:for-each>
</tr>
</table>
<xsl:for-each select="/Dictionary/translation">
<xsl:sort select="@initial" data-type="number"/>
<xsl:if test="generate-id(.)=generate-id(../translation[@initial=current()/@initial])">
<h3><p><a name="{@initial}"><xsl:value-of select="@initial"/></a></p></h3>
<!--文件内跳转目的点,引用@initial的值,与href 呼应,使得每次跳转到不同的目的点-->
<table border="1" width="700" id="table2">
<xsl:for-each select="../translation[@initial=current()/@initial]">
<xsl:sort select="search"/>
<xsl:sort select="replace"/>
<tr>
<th align="left" width="350"><xsl:value-of select="search"/></th>
<td width="350">
<xsl:for-each select="/Dictionary/translation[search=current()/search]/replace">
<xsl:if test="position()!=last()"><xsl:copy-ofselect="."/><xsl:text>;</xsl:text></xsl:if>
<xsl:if test="position() =last()"><xsl:copy-of select="."/><xsl:text></xsl:text></xsl:if>
<!--copy-of 和value-of在此处功能一样,都是显示当前节点的replace的值,利用position()和last()测试当前节点是否是最后的节点,并采取相应的操作-->
<--此处还可以利用aply-templates模板自动匹配replace,同样可以正确的显示出replace值如下
<td class="replace"><xsl:apply-templates select="replace"/></td>
................................................
..............................
......................
<xsl:template match="replace">
<xsl:value-of select="."/>
<xsl:if test="position() !=last()"><xsl:text>;</xsl:text></xsl:if>
</xsl:template>
.......................
....................--->
</xsl:for-each>
</td>
</tr>
</xsl:for-each>
</table>
</xsl:if>
</xsl:for-each>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
************************************************************
get <xsl:apply-templates select="replace">example from my friend WYL thanks here....
