文章詳情頁(yè)
匹配模式 - XSL教程 - 4
瀏覽:510日期:2022-06-04 14:50:26
<xsl:template> 元素定義了用于匹配節(jié)點(diǎn)的規(guī)則(match,其中"/"匹配整個(gè)文檔),在apply-template使用
語(yǔ)法規(guī)則為:
<xsl:template
name="name"
match="pattern"
mode="mode"
priority="number">
<!-- Content:(<xsl:param>*,template) -->
</xsl:template>
其中:
name 模板名稱
match Xpath語(yǔ)句,指定條件
mode模式,例如紅,藍(lán)等樣式
priority優(yōu)先級(jí),為數(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>
可以以列表的方式顯示用戶信息。
語(yǔ)法規(guī)則為:
<xsl:template
name="name"
match="pattern"
mode="mode"
priority="number">
<!-- Content:(<xsl:param>*,template) -->
</xsl:template>
其中:
name 模板名稱
match Xpath語(yǔ)句,指定條件
mode模式,例如紅,藍(lán)等樣式
priority優(yōu)先級(jí),為數(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>
可以以列表的方式顯示用戶信息。
標(biāo)簽:
XML/RSS
相關(guān)文章:
1. Vue v-for中的 input 或 select的值發(fā)生改變時(shí)觸發(fā)事件操作2. vue中v-model對(duì)select的綁定操作3. vue-electron中修改表格內(nèi)容并修改樣式4. React基礎(chǔ)-JSX的本質(zhì)-虛擬DOM的創(chuàng)建過(guò)程實(shí)例分析5. Asp.Net部署Docker-v指令使用詳解6. 尤大大新活petite-vue的實(shí)現(xiàn)7. vue-route路由管理的安裝與配置方法8. PHP安全-文件上傳攻擊9. Vue vee-validate插件的簡(jiǎn)單使用10. 深入理解z-index的工作原理和應(yīng)用技巧
排行榜
