XSL簡介(二)

來源:互聯網
上載者:User
文章目錄
  • XSL(二)
XSL(二)

  第一部分學了7個元素,還有24個,一個一個學吧。

  1、<xsl:import>、<xsl:include>、<xsl:apply-imports>元素
  <xsl:import>與<xsl:include>相比,兩者都須是<xsl:stylesheet>的子結點,但前者定義的模板規則優先順序比較低,且必須為第一個子結點。兩者的功能是相同的,都是將另一個定義好的XSL檔案裝入到當前XSL檔案中來。
  裝來的模板規則,由<xsl:apply-imports>指定何時何地使用。
  它們的文法分別是:

<xsl:import href="URI"/>
<xsl:apply-templates />

 

  2、<xsl:attribute>、<xsl:attribute-set>元素
  前者用以給元素增加屬性,已有同名屬性則被它替換。後者是<xsl:stylesheet>的子結點,用來定義一組屬性,將其用於整個文檔。文法如下:

<xsl:attribute name="attributename" namespace="uri"><!-- Content:template --></xsl:attribute>
<xsl:attribute-set name="name" use-attribute-sets="name-list"><!-- Content:xsl:attribute* --></xsl:attribute-set>

  namespace可選,use-attribute-sets可選,用以使用其它預定義的attribute-set.

 

  3、<xsl:param>、<xsl:call-template>、<xsl:with-param>元素
  <xsl:param>用來定義全域參數(是<xsl:styelsheet>的子點時)或局域參數(在一個模板內時),<xsl:call-template>用來調用指定的模板,<xsl:with-param>則用來調用模板或使用模板時傳遞參數。需要說明的是,with-param的name屬性的值必須與預定義的值一致。文法如下:

<xsl:param name="name" select="expression"><!-- Content:template --></xsl:param>
<xsl:call-template name="templatename"><!-- Content:xsl:with-param* --></xsl:call-template>
<xsl:with-param name="name" select="expression"><!-- Content:template --></xsl:with-param>

  其中的select都是可選的,前者的select用來指定預設值,後者可以來傳值(也可用標籤的內容傳值)。

 

  4、<xsl:variable>元素
  定義全域或局部變數,其一旦賦值,不能改動。文法:

<xsl:variable name="name" select="expression"><!-- Content:template --></xsl:variable>

 

  5、<xsl:copy>、<xsl:copy-of>元素
  兩者都複製當前節點及其命名空間,但後者還複製子結點和當前結點屬性。文法如下:

<xsl:copy-of select="expression"/>
<xsl:copy use-attribute-sets="name-list"><!-- Content:template --></xsl:copy>

其中use-attribute-sets可選。

 

  6、<xsl:comment>元素
  在結果樹中產生一個注釋結點。文法如下:

<xsl:comment><!-- Content:template --></xsl:comment>

 

  7、<xsl:decimal-format>元素
  定義那些在調用函數format-number()進行由數字向字元器轉換的過程中用到的一些特殊字元或符號。文法如下:

<xsl:decimal-format name="name" decimal-separator="char" grouping-separator="char" infinity="string"
minus-sign="char" NaN="string" percent="char" per-mille="char" zero-digit="char" digit="char" pattern-separator="char"/>

所有項是可選的。

 

  8、<xsl:element>元素
  在結果樹上產生一個元素,文法如下:

<xsl:element name="name" namespace="URI" use-attribute-sets="namelist"><!-- Content:template --></xsl:element>

其中後兩個屬性是可選的,前倆者的值可在即時運行時算出。

 

  9、<xsl:fallback>元素
  當xsl的元素不能被處理器識別時,調用fallback提供的備用程式。

<xsl:fallback><!-- Content: template --></xsl:fallback>

 

  10、<xsl:key>元素
  這是一個頂層元素,定義一個KEY供Key函數使用。

<xsl:key name="name" match="pattern" use="expression"/>

 

  11、<xsl:message>元素
  用來輸出資訊,如錯誤資訊。所有的其它元素都可出現在其內容中。

<xsl:message terminate="yes|no"> <!-- Content:template --></xsl:message>

 

  12、<xsl:namespace-alias>元素
  用來在輸出時將某命名空間替換為另一個。

<xsl:namespace-alias stylesheet-prefix="prefix|#default" result-prefix="prefix|"#default"/>

 

  13、<xsl:number>元素
  用以標明當前結點在源樹中的順序,也可以用格式化一個數。

<xsl:number count="expression" level="single|multiple|any" from="expression" value="expression" format="formatstring"
lang="languagecode" letter-value="alphabetic|traditional" grouping-separator="character" grouping-size="number"/>

 

  14、<xsl:output>元素
  用以定義output的格式,

<xsl:output method="xml|html|text|name" version="string" encoding="string" omit-xml-declaration="yes|no"
standalone="yes|no" doctype-public="string" doctype-system="string" cdata-section-elements="namelist"
indent="yes|no" media-type="string"/>

 

  15、<xsl:preserve-space>、<xsl:strip-space>元素
  兩者用來指明元素內容的空格保留還去掉。由於預設是保留的,所以只有在用了去掉時才需指明保留者。

<xsl:preserve-space elements="list-of-element-names"/>
<xsl:strip-space elements="list-of-element-names"/>

  list-of-element-names的值中可用*萬用字元。

 

  16、<xsl:processing-instruction>元素
  用來向輸出寫處理指示,如指定css檔案等。

<xsl:processing-instruction name="process-name"><!-- Content:template --></xsl:processing-instruction>

 

  17、<xsl:text>元素
  用來輸出字串常量。

<xsl:text disable-output-escaping="yes|no"> <!-- Content:#PCDATA --></xsl:text>

 

參考資料:
XSLT FAQ
http://www.dpawson.co.uk/index.html

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.