当前位置: 代码网 > it编程>网页制作>Xml > 匹配模式 - XSL教程 - 4

匹配模式 - XSL教程 - 4

2024年05月15日 Xml 我要评论
<xsl:template>元素定义了用于匹配节点的规则(match,其中"/"匹配整个文档),在apply-template使用 语法规则为: <xsl:template name
<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>

  可以以列表的方式显示用户信息。
(0)

相关文章:

版权声明:本文内容由互联网用户贡献,该文观点仅代表作者本人。本站仅提供信息存储服务,不拥有所有权,不承担相关法律责任。 如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 2386932994@qq.com 举报,一经查实将立刻删除。

发表评论

验证码:
Copyright © 2017-2025  代码网 保留所有权利. 粤ICP备2024248653号
站长QQ:2386932994 | 联系邮箱:2386932994@qq.com