匹配模式 - XSL教程 - 4
更新時間:2007年04月20日 00:00:00 作者:
<xsl:template> 元素定義了用于匹配節(jié)點(diǎn)的規(guī)則(match,其中"/"匹配整個文檔),在apply-template使用
語法規(guī)則為:
<xsl:template
name="name"
match="pattern"
mode="mode"
priority="number">
<!-- Content:(<xsl:param>*,template) -->
</xsl:template>
其中:
name 模板名稱
match Xpath語句,指定條件
mode模式,例如紅,藍(lán)等樣式
priority優(yōu)先級,為數(shù)字
例如如下的xml文件:<?xml version="1.0" encoding="GB2312"?>
<?xml:stylesheet type="text/xsl" href="UserList_template.xsl"?>
<Users>
<User IsAdmin='OK'>
<Name>5do8</Name>
<ID>1</ID>
<Contact>
<QQ>369987789</QQ>
<EMAIL>service@163.com</EMAIL>
</Contact>
</User>
<User>
<Name>cjjer</Name>
<ID>2</ID>
<Contact>
<QQ>369987789</QQ>
<EMAIL>service@163.com</EMAIL>
</Contact>
</User>
<User>
<Name>Admin</Name>
<ID>3</ID>
<Contact>
<QQ>369987789</QQ>
<EMAIL>service@163.com</EMAIL>
</Contact>
</User>
</Users>
其中使用的模板(UserList_template.xsl)為:
<?xml version="1.0" encoding="GB2312"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<h2>All User List</h2>
<xsl:apply-templates/>
</body>
</html>
</xsl:template>
<xsl:template match="User">
<p>
<xsl:apply-templates select="Name"/>
<xsl:apply-templates select="ID"/>
</p>
</xsl:template>
<xsl:template match="Name">
Name: <span style="color:#BB0000">
<xsl:value-of select="."/></span>
<br />
</xsl:template>
<xsl:template match="ID">
ID: <span style="color:#808000">
<xsl:value-of select="."/></span>
<br />
</xsl:template>
</xsl:stylesheet>
可以以列表的方式顯示用戶信息。
語法規(guī)則為:
<xsl:template
name="name"
match="pattern"
mode="mode"
priority="number">
<!-- Content:(<xsl:param>*,template) -->
</xsl:template>
其中:
name 模板名稱
match Xpath語句,指定條件
mode模式,例如紅,藍(lán)等樣式
priority優(yōu)先級,為數(shù)字
例如如下的xml文件:<?xml version="1.0" encoding="GB2312"?>
<?xml:stylesheet type="text/xsl" href="UserList_template.xsl"?>
<Users>
<User IsAdmin='OK'>
<Name>5do8</Name>
<ID>1</ID>
<Contact>
<QQ>369987789</QQ>
<EMAIL>service@163.com</EMAIL>
</Contact>
</User>
<User>
<Name>cjjer</Name>
<ID>2</ID>
<Contact>
<QQ>369987789</QQ>
<EMAIL>service@163.com</EMAIL>
</Contact>
</User>
<User>
<Name>Admin</Name>
<ID>3</ID>
<Contact>
<QQ>369987789</QQ>
<EMAIL>service@163.com</EMAIL>
</Contact>
</User>
</Users>
其中使用的模板(UserList_template.xsl)為:
<?xml version="1.0" encoding="GB2312"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<h2>All User List</h2>
<xsl:apply-templates/>
</body>
</html>
</xsl:template>
<xsl:template match="User">
<p>
<xsl:apply-templates select="Name"/>
<xsl:apply-templates select="ID"/>
</p>
</xsl:template>
<xsl:template match="Name">
Name: <span style="color:#BB0000">
<xsl:value-of select="."/></span>
<br />
</xsl:template>
<xsl:template match="ID">
ID: <span style="color:#808000">
<xsl:value-of select="."/></span>
<br />
</xsl:template>
</xsl:stylesheet>
可以以列表的方式顯示用戶信息。
相關(guān)文章
關(guān)聯(lián)數(shù)據(jù)入門——RDF應(yīng)用
語義網(wǎng)也不僅僅是把數(shù)據(jù)放在互聯(lián)網(wǎng)上,而是試圖將數(shù)據(jù)聯(lián)系起來,并產(chǎn)生數(shù)據(jù)與現(xiàn)實(shí)事物的聯(lián)系,以方便人與機(jī)器閱讀與理解這些數(shù)據(jù),感興趣的朋友可以了解下2013-02-02xml創(chuàng)建節(jié)點(diǎn)(根節(jié)點(diǎn)、子節(jié)點(diǎn))
聲明、創(chuàng)建、創(chuàng)建根節(jié)點(diǎn)、添加Books的子節(jié)點(diǎn)最后保存文檔(如果已經(jīng)存在該文件,則更新之;如果沒有,則創(chuàng)建該文件),不會的朋友可以了解下哈2013-05-05