使用 XSLT 轉換 XML
概述
內容和表現形式的分離是 XML 的一個關鍵設計特性。XML 文件的結構旨在反映和闡明內容各個方面之間重要的關係,不受需要提供任何指示關於這些資料最終如何呈現的限制。這種智慧化的結構尤其重要,因為越來越多的資料傳輸是自動化的,並且發生在透過網路連線的高度異構機器之間。
然而,最終,儲存在 XML 文件中的許多內容都需要呈現給人類讀者。由於瀏覽器提供了一個熟悉且高度靈活的介面,因此它是交付此類 XML 內容呈現版本的理想機制。Firefox 從頭開始利用各種 XML 技術構建,在其內部集成了處理原始 XML 文件和用於樣式化並將其佈局以進行 HTML 顯示的專用樣式表所需的所有機制,透過客戶端處理減少伺服器負載。
目前,Gecko(Firefox 背後的佈局引擎)支援兩種形式的 XML 樣式表。對於外觀的基本控制——字型、顏色、位置等——Gecko 使用 CSS。
我們在這裡關注的是 Gecko 支援的第二種樣式表:XSLT 樣式表。XSLT 代表可擴充套件樣式表語言/轉換,這個名稱很貼切。XSLT 允許樣式表作者以兩種重要方式轉換主要的 XML 文件:操作和排序內容,包括根據需要對其進行徹底的重新排序,以及將內容轉換為不同的格式(在 Firefox 的情況下,重點是在執行時將其轉換為 HTML,然後瀏覽器可以顯示它)。
XSLT/XPath 參考
元素
- xsl:apply-imports (支援)
- xsl:apply-templates (支援)
- xsl:attribute (支援)
- xsl:attribute-set (支援)
- xsl:call-template (支援)
- xsl:choose (支援)
- xsl:comment (支援)
- xsl:copy (支援)
- xsl:copy-of (支援)
- xsl:decimal-format (支援)
- xsl:element (支援)
- xsl:fallback (不支援)
- xsl:for-each (支援)
- xsl:if (支援)
- xsl:import (大部分支援)
- xsl:include (支援)
- xsl:key (支援)
- xsl:message (支援)
- xsl:namespace-alias (不支援)
- xsl:number (部分支援)
- xsl:otherwise (支援)
- xsl:output (部分支援)
- xsl:param (支援)
- xsl:preserve-space (支援)
- xsl:processing-instruction
- xsl:sort (支援)
- xsl:strip-space (支援)
- xsl:stylesheet (部分支援)
- xsl:template (支援)
- xsl:text (部分支援)
- xsl:transform (支援)
- xsl:value-of (部分支援)
- xsl:variable (支援)
- xsl:when (支援)
- xsl:with-param (支援)
軸
函式
- boolean() (支援)
- ceiling() (支援)
- concat() (支援)
- contains() (支援)
- count() (支援)
- current() (支援)
- document() (支援)
- element-available() (支援)
- false() (支援)
- floor() (支援)
- format-number() (支援)
- function-available() (支援)
- generate-id() (支援)
- id() (部分支援)
- key() (支援)
- lang() (支援)
- last() (支援)
- local-name() (支援)
- name() (支援)
- namespace-uri() (支援)
- normalize-space() (支援)
- not() (支援)
- number() (支援)
- position() (支援)
- round() (支援)
- starts-with() (支援)
- string() (支援)
- string-length() (支援)
- substring() (支援)
- substring-after() (支援)
- substring-before() (支援)
- sum() (支援)
- system-property() (支援)
- translate() (支援)
- true() (支援)
- unparsed-entity-url() (不支援)
進一步閱讀
原文件資訊
- 版權資訊:版權所有 © 2001-2003 Netscape。保留所有權利。
- 注意:本文轉載自 DevEdge 網站。