文章詳情頁
匹配模式 - XSL教程 - 4
瀏覽:420日期:2022-06-04 14:50:26
<xsl:template> 元素定義了用于匹配節點的規則(match,其中"/"匹配整個文檔),在apply-template使用
語法規則為:
<xsl:template
name="name"
match="pattern"
mode="mode"
priority="number">
<!-- Content:(<xsl:param>*,template) -->
</xsl:template>
其中:
name 模板名稱
match Xpath語句,指定條件
mode模式,例如紅,藍等樣式
priority優先級,為數字
例如如下的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>[email protected]</EMAIL>
</Contact>
</User>
<User>
<Name>cjjer</Name>
<ID>2</ID>
<Contact>
<QQ>369987789</QQ>
<EMAIL>[email protected]</EMAIL>
</Contact>
</User>
<User>
<Name>Admin</Name>
<ID>3</ID>
<Contact>
<QQ>369987789</QQ>
<EMAIL>[email protected]</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>
可以以列表的方式顯示用戶信息。
語法規則為:
<xsl:template
name="name"
match="pattern"
mode="mode"
priority="number">
<!-- Content:(<xsl:param>*,template) -->
</xsl:template>
其中:
name 模板名稱
match Xpath語句,指定條件
mode模式,例如紅,藍等樣式
priority優先級,為數字
例如如下的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>[email protected]</EMAIL>
</Contact>
</User>
<User>
<Name>cjjer</Name>
<ID>2</ID>
<Contact>
<QQ>369987789</QQ>
<EMAIL>[email protected]</EMAIL>
</Contact>
</User>
<User>
<Name>Admin</Name>
<ID>3</ID>
<Contact>
<QQ>369987789</QQ>
<EMAIL>[email protected]</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>
可以以列表的方式顯示用戶信息。
標簽:
XML/RSS
相關文章:
1. Java 3D的動畫展示(Part1-使用JMF)2. msxml3.dll 錯誤 800c0019 系統錯誤:-2146697191解決方法3. vue打包通過image-webpack-loader插件對圖片壓縮優化操作4. Django+Django-Celery+Celery的整合實戰5. Java高級編程:打印--學習如何使用打印服務API6. 深入理解java虛擬機-第13章-線程安全與鎖優化7. keep-Alive搭配vue-router實現緩存頁面效果的示例代碼8. 尤大大新活petite-vue的實現9. 基于Java的Socket多客戶端Client-Server聊天程序的實現10. 捕獲屏幕-編寫一個基于Java Robot類的屏幕捕獲工具
排行榜