DIV CSS 佈局教程網

 DIV+CSS佈局教程網 >> 網頁腳本 >> XML學習教程 >> XML詳解 >> 匹配模式的學習
匹配模式的學習
編輯:XML詳解     

<xsl:template>元素定義了用於匹配節點的規則(match,其中"/"匹配整個文檔),在apply-template使用

  語法規則為:

<xsl:template
name="name"
match="pattern"
mode="mode"
priority="number"> 
<!--Content:(<xsl:param>*,template)-->
</xsl:template>

  其中:

  name模板名稱

  matchXpath語句,指定條件

  mode模式,例如紅,藍等樣式

  priority優先級,為數字

  例如如下的XML文件:

<?XMLversion="1.0"encoding="GB2312"?>
<?XML:stylesheettype="text/xsl"href="UserList_template.xsl"?>
<Users>
  <UserIsAdmin='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)為:

<?XMLversion="1.0"encoding="GB2312"?>
<xsl:stylesheetversion="1.0"XMLns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:templatematch="/">
 <Html>
   <body>
   <h2>AllUserList</h2>
    <xsl:apply-templates/>
   </body>
 </Html>
</xsl:template>
<xsl:templatematch="User">
 <p>
 <xsl:apply-templatesselect="Name"/>
 <xsl:apply-templatesselect="ID"/>
 </p>
</xsl:template>
<xsl:templatematch="Name">
 Name:<spanstyle="color:#BB0000">
 <xsl:value-ofselect="."/></span>
 <br/>
</xsl:template>
<xsl:templatematch="ID">
 ID:<spanstyle="color:#808000">
 <xsl:value-ofselect="."/></span>
 <br/>
</xsl:template>
</xsl:stylesheet>

  可以以列表的方式顯示用戶信息。


XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved