播客 > 玩代码  >  匹配模式 - XSL教程 - 4  | 登录  | RSS订阅地址  | Code平台

匹配模式 - XSL教程 - 4

 
<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>


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



天气:大雨,ccdot发表于2007-4-2 10:55:11,阅读了5090次,共有个3回复.

Greetings to all. 
 
Prompt the best online shop on sale of Books.

careybagsbon post in 2007-11-19 22:56:53 #1  

How to Record XBox 360 Games on hdd??? 
Pls, help me!

sizeaspem post in 2008-3-31 12:45:12 #2  

if u can level you qq numder,maybe i can try to do something .

ccdot post in 2008-3-31 14:46:30 #3  
  1. 想要转载我文章的人滚远远的,能想多远,就滚多远。
  2. 不要提交任何带有网址URL信息的评论.
  3. 需要更多信息?请使用站内搜索,郁闷了?听听我在听什么吧!
用户名:*验证:看不清楚请点击刷新验证码*
内容: