XSLT.Cookbook2 學習筆記1--XPath

          Posted on 2006-06-02 16:42 飛馬 閱讀(166) 評論(0)  編輯  收藏 所屬分類: XML

          [ 引文 1 XSLT XPath 的作用 ]

          In XSLT 1.0, XPath plays three crucial roles

          ?First, it is used within templates for addressing into the document to extract data as it is being transformed.

          Second, XPath syntax is used as a pattern language in the matching rules for templates.

          Third, it is used to perform simple math and string manipulations via built-in XPath operators and functions.

          XSLT 2.0 retains and strengthens this intimate connection with XPath 2.0 by drawing heavily on the new computational abilities of XPath 2.0.

          [ 引文 2 當前節點的設置 ]

          In XSLT, the context is set via:

          ·???????? a template match (<xsl:template match="x"> ... </xsl:template>)

          ·???????? xsl:for-each

          ·???????? xsl:apply-templates

          xsl:template xsl:apply-templates

          前者相當于定義函數,后者相當于調用函數。

          xsl:template 中, match 屬性采用了 XPath 表達式,用來確定模板的適用對象。對 match 屬性的設置時, //X 等價于 X

          xsl:apply-templates 中, select 屬性采用了 XPath 表達式,用來選擇要應用模板的節點。如果省略了 select 屬性,則表示當前節點的所有后代節點都應用模板,如果有些節點沒用通過 xsl:template 定義模板,則采用默認模板(注: IE 中存在默認模板)。設置 select 屬性時,要從文檔根( / )開始的絕對路徑來選擇節點,但是 / 可以省略。此處和上面 match 屬性差別很大,注意區分。

          注意:

          1 <xsl:template match="/">

          ?? ?? ? ?<xsl:apply-templates select="/" />

          </xsl:template>

          上面語句會引起遞歸調用模板,死循環。

          2 )如果在 XSL 文件中沒有對應根的模板,即沒有 <xsl:template match="/"> ,則其他的模板都會被使用。但是,如果文件中存在對應根的模板,除非使用 <xsl:apply-templates select=" …… " /> ,否則其他的模板都不會被使用。 這是因為,如果沒有對應根的模板, IE 會采用默認的對應根的模板,而這個默認的模板中使用了 <xsl:apply-templates select=" …… " /> 。這類似于 Java 中默認構造函數的重寫,如果我們沒有定義,就使用默認的。


          只有注冊用戶登錄后才能發表評論。


          網站導航:
           

          posts - 1, comments - 0, trackbacks - 0, articles - 5

          Copyright © 飛馬

          主站蜘蛛池模板: 西藏| 云浮市| 巴南区| 兴仁县| 驻马店市| 黔东| 瓦房店市| 云阳县| 磐安县| 应城市| 全州县| 潞城市| 福清市| 汶上县| 阜宁县| 汉源县| 都江堰市| 西畴县| 梧州市| 德州市| 宁海县| 宝坻区| 东乡族自治县| 义乌市| 华池县| 聂荣县| 金溪县| 广西| 罗田县| 大同市| 武冈市| 图木舒克市| 平昌县| 东城区| 镇赉县| 独山县| 紫阳县| 轮台县| 务川| 台北市| 额敏县|