文章详情页
匹配模式 - XSL教程 - 4
浏览:673日期: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>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>
可以以列表的方式显示用户信息。
语法规则为:
<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>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>
可以以列表的方式显示用户信息。
标签:
XML/RSS
相关文章:
1. 《CSS3实战》笔记--渐变设计(一)2. 基于Java的Socket多客户端Client-Server聊天程序的实现3. vue中keep-alive内置组件缓存的实例代码4. vue中v-for循环选中点击的元素并对该元素添加样式操作5. vue完美实现el-table列宽自适应6. Spring Cloud 整合Apache-SkyWalking实现链路跟踪的方法7. SpringBoot--- SpringSecurity进行注销权限控制的配置方法8. Vue过滤器,生命周期函数和vue-resource简单介绍9. 三十分钟掌握STL-教程10. python-xpath获取html文档的部分内容
排行榜