亚洲香蕉成人av网站在线观看_欧美精品成人91久久久久久久_久久久久久久久久久亚洲_热久久视久久精品18亚洲精品_国产精自产拍久久久久久_亚洲色图国产精品_91精品国产网站_中文字幕欧美日韩精品_国产精品久久久久久亚洲调教_国产精品久久一区_性夜试看影院91社区_97在线观看视频国产_68精品久久久久久欧美_欧美精品在线观看_国产精品一区二区久久精品_欧美老女人bb

首頁 > 開發 > CSS > 正文

將XSLT作為HTML的樣式表的使用方法示例

2024-07-11 09:00:34
字體:
來源:轉載
供稿:網友

 簡介  

當聽到樣式表這個詞時,您可能會想到 CSS 樣式表。XSLT 樣式表通常用于 XML 轉換,比如在 Web 服務之間映射數據。因為 XSLT 非常適合此用途,所以創建了頂層元素 <stylesheet> 的 <xsl:transform> 別名,雖然這很少使用。這種 XSLT 轉換的輸入結構與輸出結構有很大的不同。最重要的是,命名空間的不同。

  XSLT 樣式表的輸入結構與輸出結構相似,但卻更簡單些。其中已經擴充了一些標記,但大部分標記只是原樣復制到輸出。輸入和輸出的命名空間是相同的 (HTML)。輸入文檔也可以包含樣式表指令(比如創建腳注),這些指令屬于另一個命名空間,不會傳遞到輸出中。
常用縮略語

CSS:級聯樣式表
XHTML:可擴展超文本標記語言
XPath:XML 路徑語言
XSLT:可擴展樣式表語言轉換

  在本文中,我們將學習如何使用 XSLT 樣式表擴充 XHTML 文檔。文中的示例展示了如何使用指令,如何引用其他源文檔的部分,以及如何使用鏈接在主文檔中導航。此外,我們還探索了頁面的解釋和編譯之間的區別。
CSS 樣式表的局限性

  XSLT 樣式表不會阻止您使用其他技術,比如 JavaScript 或 CSS。CSS 適用于字體、加粗、顏色、間距等。它不適合將來自不同位置的信息組合在一起,比如腳注、模塊或生成一個目錄。這正是 XSLT 的用武之地,它補充而不是替代了 CSS。
XSLT 用途示例

  實際上,您可以將 XSLT 代碼集中在一個文件中。為了簡單起見,本文中的每個示例均位于一個獨立的 XSLT 文件中,除了一些必要的代碼。清單 1 給出了必需的代碼。

  清單 1. 必需的代碼(位于 samples/common.xml 中)

 

XML/HTML Code復制內容到剪貼板
  1. <s:stylesheet
  2. <span style="width: auto; height: auto; float: none;" id="24_nwp"><a style="text-decoration: none;" mpid="24" target="_blank" href="http://cpro.baidu.com/cpro/ui/uijs.php?adclass=0&app_id=0&c=news&cf=1001&ch=0&di=128&fv=0&is_app=0&jk=d14555d819ab7000&k=xml&k0=
  3. xml&kdi0=0&luki=10&n=10&p=baidu&q=06011078_cpr&rb=0&rs=1&seller_id=1&sid=70ab19d85545d1&ssp2=
  4. 1&stid=0&t=tpclicked3_hc&tu=u1922429&u=http%3A%2F%2Fwww%2Eadmin10000%2Ecom%2Fdocument%2
  5. F1117%2Ehtml&urlid=0" id="24_nwl"><span style="color:#0000ff;font-size:14px;width:auto;height:auto;float:none;">xml</span></a></span>ns="http://www.w3.org/1999/xhtml"
  6. xmlns:h="http://www.w3.org/1999/xhtml"
  7. xmlns:a="http://sourceforge.net/projects/arbalo/"
  8. xmlns:s="http://www.w3.org/1999/XSL/Transform"
  9. exclude-result-prefixes="a h"
  10. version="1.0"
  11. >
  12. <s:template match="h:<span style="width: auto; height: auto; float: none;" id="25_nwp"><a style="text-decoration: none;" mpid="25" target="_blank" href="http://cpro.baidu.com/cpro/ui/uijs.php?adclass=0&app_id=0&c=news&cf=1001&ch=0&di=128&fv=0&is_app=0&jk=d14555d819ab7000&k=head&k0=
  13. head&kdi0=0&luki=9&n=10&p=baidu&q=06011078_cpr&rb=0&rs=1&seller_id=1&sid=70ab19d85545d1&ssp2
  14. =1&stid=0&t=tpclicked3_hc&tu=u1922429&u=http%3A%2F%2Fwww%2Eadmin10000%2Ecom%2Fdocument%
  15. 2F1117%2Ehtml&urlid=0" id="25_nwl"><span style="color:#0000ff;font-size:14px;width:auto;height:auto;float:none;">head</span></a></span>">
  16. <s:copy>
  17. <s:apply-templates select="@*|node()"/>
  18. <meta
  19. http-equiv="content-type"
  20. content="text/html;charset=UTF-8" />
  21. <link
  22. href="common.<span style="width: auto; height: auto; float: none;" id="26_nwp"><a style="text-decoration: none;" mpid="26" target="_blank" href="http://cpro.baidu.com/cpro/ui/uijs.php?adclass=0&app_id=0&c=news&cf=1001&ch=0&di=128&fv=0&is_app=0&jk=d14555d819ab7000&k=css&k
  23. 0=css&kdi0=0&luki=8&n=10&p=baidu&q=06011078_cpr&rb=0&rs=1&seller_id=1&sid=70ab19d85545d1&ss
  24. p2=1&stid=0&t=tpclicked3_hc&tu=u1922429&u=http%3A%2F%2Fwww%2Eadmin10000%2Ecom%2Fdocument%
  25. 2F1117%2Ehtml&urlid=0" id="26_nwl"><span style="color:#0000ff;font-size:14px;width:auto;height:auto;float:none;">css</span></a></span>"
  26. rel="stylesheet"
  27. type="text/css" />
  28. </s:copy>
  29. </s:template>
  30.  
  31. <s:template match="*">
  32. <s:copy>
  33. <s:copy-of select="@*"/>
  34. <s:apply-templates/>
  35. </s:copy>
  36. </s:template>
  37. </s:stylesheet>

  XHTML 的命名空間定義了兩次:默認定義和 h:。默認命名空間用于編寫輸出 XHTML 標記,其中應該避免使用命名空間前綴。h: 用在 XPath 表達式中。

  本文使用 XSLT 1.0 版本。目前,大部分瀏覽器都無法解釋 XSLT 2.0。但是,如果 XSLT 運行在服務器上,那么它可能是一個實用的選擇。XSLT 2.0 還提供了:

XPATH 2.0(if…then…else 和許多內置的函數)
內置和用戶編寫的 XPATH 函數
分組

  在 清單 1 中:

s:template match="head" 擴充了源文檔的 head 一節,添加了一個 CSS 樣式表的鏈接。即使 UTF-8 是在 XML 中的默認編碼,一些瀏覽器也需要內容類型才能呈現它。
s:template match="*" 是默認的詳細副本。原則上,所有內容都會復制到目標文檔中。如果遺漏了此模板,只會將標記的文本內容復制到目標文檔。不會復制處理指令節點。

  本文中的所有其他示例都是導入 common.xsl 的獨立文件。
擴充

  通過擴充,添加了一個未在源文檔中顯式請求的特性。一個示例是 清單 1 中的 CSS 樣式表的鏈接。嘗試另一個示例,向每個內部鏈接添加一個小箭頭 (^ v),指明目標在它之前還是之后。清單 2 給出了該樣式表。

  清單 2. 樣式表(在 samples/linkUpDown.xsl 中)

 

XML/HTML Code復制內容到剪貼板
  1. <s:stylesheet
  2. <span style="width: auto; height: auto; float: none;" id="22_nwp"><a style="text-decoration: none;" mpid="22" target="_blank" href="http://cpro.baidu.com/cpro/ui/uijs.php?adclass=0&app_id=0&c=news&cf=1001&ch=0&di=128&fv=0&is_app=0&jk=d14555d819ab7000&k=xml&k0
  3. =xml&kdi0=0&luki=10&n=10&p=baidu&q=06011078_cpr&rb=0&rs=1&seller_id=1&sid=70ab19d85545d1&ss
  4. p2=1&stid=0&t=tpclicked3_hc&tu=u1922429&u=http%3A%2F%2Fwww%2Eadmin10000%2Ecom%2Fdocum
  5. ent%2F1117%2Ehtml&urlid=0" id="22_nwl"><span style="color:#0000ff;font-size:14px;width:auto;height:auto;float:none;">xml</span></a></span>ns="http://www.w3.org/1999/xhtml"
  6. xmlns:h="http://www.w3.org/1999/xhtml"
  7. xmlns:s="http://www.w3.org/1999/XSL/Transform"
  8. version="1.0"
  9. >
  10. <s:import href="common.xsl"/>
  11. <s:template match="h:a[starts-with(@href,'#')]">
  12. <s:copy>
  13. <s:copy-of select="@*"/>
  14. <s:variable name="name" select="substring-after(@href,'#')"/>
  15. <s:choose>
  16. <s:when test="preceding::h:a[@name=$name]">
  17. <s:text>^</s:text>
  18. </s:when>
  19. <s:when test="following::h:a[@name=$name]">
  20. <s:text>v</s:text>
  21. </s:when>
  22. </s:choose>
  23. <s:apply-templates/>
  24. </s:copy>
  25. </s:template>
  26. </s:stylesheet>

  首先,導入清單 2 中的通用樣式表。模板與內部鏈接(以 '#' 開頭)相匹配。如果鏈接指向的錨點位于鏈接之前,那么使用一個向上箭頭擴充該鏈接(如果情況相反,則使用向下箭頭)。

  s:copy-of 和 s:apply-templates 可確保不會沿途丟下任何內容。

  清單 3 給出了一個示例文檔(其中包含內部鏈接),它經過了清單 2 中的樣式表進行擴充。

  清單 3. 源文檔(在 samples/linkUpDown.xml 中)

XML/HTML Code復制內容到剪貼板
  1. <?<span style="width: auto; height: auto; float: none;" id="20_nwp"><a style="text-decoration: none;" mpid="20" target="_blank" href="http://cpro.baidu.com/cpro/ui/uijs.php?adclass=0&app_id=0&c=news&cf=1001&ch=0&di=128&fv=0&is_app=0&jk=d14555d819ab7000&k=xml&k0=x
  2. ml&kdi0=0&luki=10&n=10&p=baidu&q=06011078_cpr&rb=0&rs=1&seller_id=1&sid=70ab19d85545d1&ssp2=
  3. 1&stid=0&t=tpclicked3_hc&tu=u1922429&u=http%3A%2F%2Fwww%2Eadmin10000%2Ecom%2Fdocument%
  4. 2F1117%2Ehtml&urlid=0" id="20_nwl"><span style="color:#0000ff;font-size:14px;width:auto;height:auto;float:none;">xml</span></a></span>-stylesheet href="linkUpDown.xsl" type="text/xsl"?>
  5. <html xmlns="http://www.w3.org/1999/xhtml">
  6. <<span style="width: auto; height: auto; float: none;" id="21_nwp"><a style="text-decoration: none;" mpid="21" target="_blank" href="http://cpro.baidu.com/cpro/ui/uijs.php?adclass=0&app_id=0&c=news&cf=1001&ch=0&di=128&fv=0&is_app=0&jk=d14555d819ab7000&k=head&k0=
  7. head&kdi0=0&luki=9&n=10&p=baidu&q=06011078_cpr&rb=0&rs=1&seller_id=1&sid=70ab19d85545d1&ssp2
  8. =1&stid=0&t=tpclicked3_hc&tu=u1922429&u=http%3A%2F%2Fwww%2Eadmin10000%2Ecom%2Fdocument%
  9. 2F1117%2Ehtml&urlid=0" id="21_nwl"><span style="color:#0000ff;font-size:14px;width:auto;height:auto;float:none;">head</span></a></span>/>
  10. <body>
  11. <a name="a"/>
  12. <p>This link goes <a href="vb">downward.</a></p>
  13. <br/>
  14. <p>Reduce the size of the window to verify the link really works.</p>
  15. <br/>
  16. <a name="b"/>
  17. <p>This link goes <a href="^a">upward.</a>
  18. </p>
  19. </body>
  20. </html>

  目標文檔看起來相同,除了清單 4 中的條目。
清單 4. 目標文檔(在 samples/linkUpDown.html 中)

XML/HTML Code復制內容到剪貼板
  1. … <a href="#b">v downwards.</a> …
  2. … <a href="#a">^ upwards.</a> …

指令

  您可以在源文檔中添加一些指令,告訴樣式表執行何種操作。它們屬于另一個命名空間(在本例中為前綴 a:),不會被復制到目標文檔。

  在清單 5 中,源文檔中任何地方的指令標記 a:ref 都會創建一個腳注。

  清單 5. 樣式表(在 samples/footnote.xsl 中)

XML/HTML Code復制內容到剪貼板
  1. <s:stylesheet
  2. <span style="width: auto; height: auto; float: none;" id="19_nwp"><a style="text-decoration: none;" mpid="19" target="_blank" href="http://cpro.baidu.com/cpro/ui/uijs.php?adclass=0&app_id=0&c=news&cf=1001&ch=0&di=128&fv=0&is_app=0&jk=d14555d819ab7000&k=xml&k0
  3. =xml&kdi0=0&luki=10&n=10&p=baidu&q=06011078_cpr&rb=0&rs=1&seller_id=1&sid=70ab19d85545d1&ssp
  4. 2=1&stid=0&t=tpclicked3_hc&tu=u1922429&u=http%3A%2F%2Fwww%2Eadmin10000%2Ecom%2Fdocumen
  5. t%2F1117%2Ehtml&urlid=0" id="19_nwl"><span style="color:#0000ff;font-size:14px;width:auto;height:auto;float:none;">xml</span></a></span>ns="http://www.w3.org/1999/xhtml"
  6. xmlns:a="http://sourceforge.net/projects/arbalo/"
  7. xmlns:h="http://www.w3.org/1999/xhtml"
  8. xmlns:s="http://www.w3.org/1999/XSL/Transform"
  9. version="1.0"
  10. >
  11. <s:import href="common.xsl"/>
  12. <s:template match="h:body">
  13. <s:copy>
  14. <s:apply-templates select="@*|node()"/
  15. <!-- put the footnotes at the end
  16. if there is no a:references directive -->
  17. <s:if test="not(descendant::a:references)">
  18. <s:call-template name="references"/>
  19. </s:if>
  20. </s:copy>
  21. </s:template>
  22. <!-- Create a footnote -->
  23. <s:template match="a:ref">
  24. <s:variable
  25. name="number"
  26. select="count(preceding::a:ref) + 1"/>
  27. <a name="ref-{$number}"></a>
  28. <a class="footnote" href="#reference-{$number}">
  29. <s:value-of select="concat('v ',$number)"/>
  30. </a>
  31. </s:template>
  32. <!-- if a:reference is missing, assume it at the end of the body -->
  33. <s:template match="a:references" name="references">
  34. <hr/>
  35. <s:for-each select="//a:ref">
  36. <s:variable name="number" select="count(preceding::a:ref) + 1"/>
  37. <p>
  38. <a name="reference-{$number}"></a>
  39. <a class="footnote" href="#ref-{$number}">
  40. <s:value-of select="concat(' ^',$number)"/>
  41. </a>
  42. <s:apply-templates/>
  43. </p>
  44. </s:for-each>
  45. </s:template>
  46. </s:stylesheet>

  使用源文檔中的 a:references 指令,名為 references 的模板會在模板與該指令匹配的地方分配腳注。如果缺少這樣一個指令,第一個與 body 匹配的模板會在 body 的末尾分配腳注,方法是調用名為 references 的相同模板。在兩種情況下,都會列出腳注的內容,并生成一個由向上箭頭表示的向上鏈接。

  第二個模板(匹配 a:ref)使用向下箭頭創建腳注的鏈接。腳注具有編號。這里忽略了它的內容。

  class="footnote" 屬性在 XSLT 轉換之后由一個 CSS 樣式表解析,該樣式表鏈接在 XSLT 樣式表 common.xsl 中。

  清單 6 中的源文檔使用 a:ref 指令創建腳注。

  清單 6. 源文檔(在 samples/footnote.xml 中)

XML/HTML Code復制內容到剪貼板
  1. <?<span style="width: auto; height: auto; float: none;" id="17_nwp"><a style="text-decoration: none;" mpid="17" target="_blank" href="http://cpro.baidu.com/cpro/ui/uijs.php?adclass=0&app_id=0&c=news&cf=1001&ch=0&di=128&fv=0&is_app=0&jk=d14555d819ab7000&k=xml&k0=x
  2. ml&kdi0=0&luki=10&n=10&p=baidu&q=06011078_cpr&rb=0&rs=1&seller_id=1&sid=70ab19d85545d1&ssp2=1
  3. &stid=0&t=tpclicked3_hc&tu=u1922429&u=http%3A%2F%2Fwww%2Eadmin10000%2Ecom%2Fdocument%2F
  4. 1117%2Ehtml&urlid=0" id="17_nwl"><span style="color:#0000ff;font-size:14px;width:auto;height:auto;float:none;">xml</span></a></span>-stylesheet href="footnote.xsl" type="text/xsl"?>
  5. <html
  6. xmlns="http://www.w3.org/1999/xhtml"
  7. xmlns:a="http://sourceforge.net/projects/arbalo/"
  8. >
  9. <<span style="width: auto; height: auto; float: none;" id="18_nwp"><a style="text-decoration: none;" mpid="18" target="_blank" href="http://cpro.baidu.com/cpro/ui/uijs.php?adclass=0&app_id=0&c=news&cf=1001&ch=0&di=128&fv=0&is_app=0&jk=d14555d819ab7000&k=head&k0
  10. =head&kdi0=0&luki=9&n=10&p=baidu&q=06011078_cpr&rb=0&rs=1&seller_id=1&sid=70ab19d85545d1&ss
  11. p2=1&stid=0&t=tpclicked3_hc&tu=u1922429&u=http%3A%2F%2Fwww%2Eadmin10000%2Ecom%2Fdocum
  12. ent%2F1117%2Ehtml&urlid=0" id="18_nwl"><span style="color:#0000ff;font-size:14px;width:auto;height:auto;float:none;">head</span></a></span>/>
  13. <body>
  14. <p>
  15. This example looks a little scientific
  16. <a:ref>
  17. From Latin
  18. <em>scientia</em>
  19. </a:ref>
  20. and academic
  21. <a:ref>From Greek akademia</a:ref>.
  22. </p>
  23. <p>
  24. Do you know why?
  25. <a:ref>
  26. It uses
  27. <em>footnotes</em>.
  28. </a:ref>
  29. </p>
  30. <p>Reduce size of window to verify links are generated.</p>
  31.  
  32.  
  33. </body>
  34. </html>

  目標文檔將腳注列表包含在底部,如清單 7 所示。

  清單 7. 目標文檔(在 samples/footnote.html 中)

 

XML/HTML Code復制內容到剪貼板
  1. <html
  2. <span style="width: auto; height: auto; float: none;" id="14_nwp"><a style="text-decoration: none;" mpid="14" target="_blank" href="http://cpro.baidu.com/cpro/ui/uijs.php?adclass=0&app_id=0&c=news&cf=1001&ch=0&di=128&fv=0&is_app=0&jk=d14555d819ab7000&k=xml&k0=
  3. xml&kdi0=0&luki=10&n=10&p=baidu&q=06011078_cpr&rb=0&rs=1&seller_id=1&sid=70ab19d85545d1&ssp
  4. 2=1&stid=0&t=tpclicked3_hc&tu=u1922429&u=http%3A%2F%2Fwww%2Eadmin10000%2Ecom%2Fdocument
  5. %2F1117%2Ehtml&urlid=0" id="14_nwl"><span style="color:#0000ff;font-size:14px;width:auto;height:auto;float:none;">xml</span></a></span>ns="http://www.w3.org/1999/xhtml"
  6. xmlns:h="http://www.w3.org/1999/xhtml"
  7. xmlns:a="http://sourceforge.net/projects/arbalo/">
  8. <<span style="width: auto; height: auto; float: none;" id="15_nwp"><a style="text-decoration: none;" mpid="15" target="_blank" href="http://cpro.baidu.com/cpro/ui/uijs.php?adclass=0&app_id=0&c=news&cf=1001&ch=0&di=128&fv=0&is_app=0&jk=d14555d819ab7000&k=head&k0=
  9. head&kdi0=0&luki=9&n=10&p=baidu&q=06011078_cpr&rb=0&rs=1&seller_id=1&sid=70ab19d85545d1&ssp2
  10. =1&stid=0&t=tpclicked3_hc&tu=u1922429&u=http%3A%2F%2Fwww%2Eadmin10000%2Ecom%2Fdocument
  11. %2F1117%2Ehtml&urlid=0" id="15_nwl"><span style="color:#0000ff;font-size:14px;width:auto;height:auto;float:none;">head</span></a></span>><link type="text/<span style="width: auto; height: auto; float: none;" id="16_nwp"><a style="text-decoration: none;" mpid="16" target="_blank" href="http://cpro.baidu.com/cpro/ui/uijs.php?adclass=0&app_id=0&c=news&cf=1001&ch=0&di=128&fv=0&is_app=0&jk=d14555d819ab7000&k=css&k0=cs
  12. s&kdi0=0&luki=8&n=10&p=baidu&q=06011078_cpr&rb=0&rs=1&seller_id=1&sid=70ab19d85545d1&ssp2=1&
  13. stid=0&t=tpclicked3_hc&tu=u1922429&u=http%3A%2F%2Fwww%2Eadmin10000%2Ecom%2Fdocument%2F1
  14. 117%2Ehtml&urlid=0" id="16_nwl"><span style="color:#0000ff;font-size:14px;width:auto;height:auto;float:none;">css</span></a></span>" rel="stylesheet" href="common.css"/></head>
  15. <body>
  16. <p>This example looks a little scientific
  17. <a name="ref-1"/><a href="#reference-1" class="footnote">v 1</a>
  18. and academic.
  19. <a name="ref-2"/><a href="#reference-2" class="footnote">v 2lt;/a>
  20. </p>
  21. <p>Do you know why?
  22. <a name="ref-3"/><a href="#reference-3" class="footnote">v 3</a>
  23. </p>
  24. <p>Reduce size of window to verify links are generated.</p>
  25. br/><br/>
  26. <hr/>
  27. <p><a name="reference-1"/><a href="#ref-1" class="footnote"> ^1</a>
  28. From Latin
  29. <em>scientia</em>
  30. </p>
  31. <p><a name="reference-2"/>
  32. <a href="#ref-2" class="footnote"> ^2</a>From Greek akademia</p>
  33. <p><a name="reference-3"/><a href="#ref-3" class="footnote"> ^3</a>
  34. It uses
  35. <em>footnotes</em>.
  36. </p>
  37. </body>
  38. </html>

突破源文檔的邊界

  也可引用其他源文檔的其中一些部分。a:include 指令包含一個可能屬于另一個源文檔的元素并轉換它,如清單 8 所示。

  清單 8. 樣式表(在 samples/include.xsl 中)

 

XML/HTML Code復制內容到剪貼板
  1. <s:stylesheet
  2. <span style="width: auto; height: auto; float: none;" id="12_nwp"><a style="text-decoration: none;" mpid="12" target="_blank" href="http://cpro.baidu.com/cpro/ui/uijs.php?adclass=0&app_id=0&c=news&cf=1001&ch=0&di=128&fv=0&is_app=0&jk=d14555d819ab7000&k=xml&k0
  3. =xml&kdi0=0&luki=10&n=10&p=baidu&q=06011078_cpr&rb=0&rs=1&seller_id=1&sid=70ab19d85545d1&s
  4. sp2=1&stid=0&t=tpclicked3_hc&tu=u1922429&u=http%3A%2F%2Fwww%2Eadmin10000%2Ecom%2Fdocu
  5. ment%2F1117%2Ehtml&urlid=0" id="12_nwl"><span style="color:#0000ff;font-size:14px;width:auto;height:auto;float:none;">xml</span></a></span>ns="http://www.w3.org/1999/xhtml"
  6. xmlns:a="http://sourceforge.net/projects/arbalo/"
  7. xmlns:s="http://www.w3.org/1999/XSL/Transform"
  8. version="1.0"
  9. >
  10. <s:import href="common.xsl"/>
  11. <s:template match="a:include">
  12. <s:choose>
  13. <s:when test="0!=string-length(@src)">
  14. <s:apply-templates
  15. select="document(@src)//*[@id=current()/@refid]"/>
  16. </s:when>
  17. <s:when test="not(@<span style="width: auto; height: auto; float: none;" id="13_nwp"><a style="text-decoration: none;" mpid="13" target="_blank" href="http://cpro.baidu.com/cpro/ui/uijs.php?adclass=0&app_id=0&c=news&cf=1001&ch=0&di=128&fv=0&is_app=0&jk=d14555d819ab7000&k=src&k0
  18. =src&kdi0=0&luki=7&n=10&p=baidu&q=06011078_cpr&rb=0&rs=1&seller_id=1&sid=70ab19d85545d1&ss
  19. p2=1&stid=0&t=tpclicked3_hc&tu=u1922429&u=http%3A%2F%2Fwww%2Eadmin10000%2Ecom%2Fdocu
  20. ment%2F1117%2Ehtml&urlid=0" id="13_nwl"><span style="color:#0000ff;font-size:14px;width:auto;height:auto;float:none;">src</span></a></span>) and //a:default[1]/@src">
  21. <s:apply-templates
  22. select="document(//a:default[1]/@src)//*[@id=current()/@refid]"/>
  23. </s:when>
  24. <s:when test="0=string-length(@src) or not(//a:default[1]/@src)">
  25. <s:apply-templates
  26. select="//*[@id=current()/@refid]"/>
  27. </s:when>
  28. </s:choose>
  29. </s:template>
  30. </s:stylesheet>

  源文檔中的一個 a:include 指令引用源元素的 id。包含該元素的文檔可在一個 src 屬性中命名。如果缺少該屬性,將使用 a:default 指令的 src 屬性。如果在任何地方都沒有 src 屬性,則使用同一個源文檔。因此,refid 會引用 id 來避免無限的遞歸。

  導入的元素可能具有一種復雜的類型,并在包含 (apply-templates)之后進行轉換。清單 9、清單 10 和清單 11 給出了示例。

  清單 9. 源文檔(在 samples/include.xml 中)

 

XML/HTML Code復制內容到剪貼板
  1. <?<span style="width: auto; height: auto; float: none;" id="7_nwp"><a style="text-decoration: none;" mpid="7" target="_blank" href="http://cpro.baidu.com/cpro/ui/uijs.php?adclass=0&app_id=0&c=news&cf=1001&ch=0&di=128&fv=0&is_app=0&jk=d14555d819ab7000&k=xml&k0=
  2. xml&kdi0=0&luki=10&n=10&p=baidu&q=06011078_cpr&rb=0&rs=1&seller_id=1&sid=70ab19d85545d1&ssp
  3. 2=1&stid=0&t=tpclicked3_hc&tu=u1922429&u=http%3A%2F%2Fwww%2Eadmin10000%2Ecom%2Fdocume
  4. nt%2F1117%2Ehtml&urlid=0" id="7_nwl"><span style="color:#0000ff;font-size:14px;width:auto;height:auto;float:none;">xml</span></a></span>-stylesheet href="include.xsl" type="text/xsl
  5. "?>
  6. <html
  7. xmlns="http://www.w3.org/1999/xhtml"
  8. xmlns:a="http://sourceforge.net/projects/arbalo/">
  9. <<span style="width: auto; height: auto; float: none;" id="8_nwp"><a style="text-decoration: none;" mpid="8" target="_blank" href="http://cpro.baidu.com/cpro/ui/uijs.php?adclass=0&app_id=0&c=news&cf=1001&ch=0&di=128&fv=0&is_app=0&jk=d14555d819ab7000&k=head&k0=
  10. head&kdi0=0&luki=9&n=10&p=baidu&q=06011078_cpr&rb=0&rs=1&seller_id=1&sid=70ab19d85545d1&ssp2
  11. =1&stid=0&t=tpclicked3_hc&tu=u1922429&u=http%3A%2F%2Fwww%2Eadmin10000%2Ecom%2Fdocument%
  12. 2F1117%2Ehtml&urlid=0" id="8_nwl"><span style="color:#0000ff;font-size:14px;width:auto;height:auto;float:none;">head</span></a></span>>
  13. <a:default <span style="width: auto; height: auto; float: none;" id="9_nwp"><a style="text-decoration: none;" mp
  14. id="9" target="_blank" href="http://cpro.baidu.com/cpro/ui/uijs.php?adclass=0&app_id=0&c=news&cf=1001&ch=0&di=128&fv=0&is_app=0&jk=d14555d819ab7000&k=src&k0=s
  15. rc&kdi0=0&luki=7&n=10&p=baidu&q=06011078_cpr&rb=0&rs=1&seller_id=1&sid=70ab19d85545d1&ssp2=1
  16. &stid=0&t=tpclicked3_hc&tu=u1922429&u=http%3A%2F%2Fwww%2Eadmin10000%2Ecom%2Fdocument%2
  17. F1117%2Ehtml&urlid=0" id="9_nwl"><span style="color:#0000ff;font-size:14px;width:auto;height:auto;float:none;">src</span></a></span>="includedY.xml"/>
  18. </head>
  19. <body>
  20. <p>The following text is included:</p>
  21. <a:include refid="x" src="includedX.xml"/>
  22. <a:include refid="y1"/>
  23. <p id="i"><span style="width: auto; height: auto; float: none;" id="10_nwp"><a style="text-decoration: none;" mpid="10" target="_blank" href="http://cpro.baidu.com/cpro/ui/uijs.php?adclass=0&app_id=0&c=news&cf=1001&ch=0&di=128&fv=0&is_app=0&jk=d14555d819ab7000&k=double&
  24. k0=double&kdi0=0&luki=6&n=10&p=baidu&q=06011078_cpr&rb=0&rs=1&seller_id=1&sid=70ab19d85545d
  25. 1&ssp2=1&stid=0&t=tpclicked3_hc&tu=u1922429&u=http%3A%2F%2Fwww%2Eadmin10000%2Ecom%2Fd
  26. ocument%2F1117%2Ehtml&urlid=0" id="10_nwl"><span style="color:#0000ff;font-size:14px;width:auto;height:auto;float:none;">double</span></a></span></p>
  27. <a:include refid="y2"/>
  28. <a:include refid="i" src=""/>
  29. </body>
  30. </html>

  清單 10. 源文檔的部分(在 samples/includeY.xml 中)

XML/HTML Code復制內容到剪貼板
  1. <h2 id="y2">I'm the <em>included</em> h2</h2>
  2. <h1 id="y1">I'm the <em>included</em> h1</h1>

  清單 11. 目標文檔(在 samples/include.html 中)

XML/HTML Code復制內容到剪貼板
  1. <body>
  2. <p>The following text is included:</p>
  3. <p id="x">I'm the <em>included</em> paragraph.</p>
  4. <h1 id="y1">I'm the <em>included</em> h1</h1>
  5. <p id="i"><span style="width: auto; height: auto; float: none;" id="6_nwp"><a style="text-decoration: none;" mpi
  6. d="6" target="_blank" href="http://cpro.baidu.com/cpro/ui/uijs.php?adclass=0&app_id=0&c=news&cf=1001&ch=0&di=128&fv=0&is_app=0&jk=d14555d819ab7000&k=double&k
  7. 0=double&kdi0=0&luki=6&n=10&p=baidu&q=06011078_cpr&rb=0&rs=1&seller_id=1&sid=70ab19d85545d1&s
  8. sp2=1&stid=0&t=tpclicked3_hc&tu=u1922429&u=http%3A%2F%2Fwww%2Eadmin10000%2Ecom%2Fdocume
  9. nt%2F1117%2Ehtml&urlid=0" id="6_nwl"><span style="color:#0000ff;font-size:14px;width:auto;height:auto;float:none;">double</span></a>
  10. </span></p>
  11. <h2 id="y2">I'm the <em>included</em> h2</h2>
  12. <p id="i">double</p>
  13. </body>
  14. </html>

主文檔和導航

  如果您有一個包含多個頁面的演示,有一個主文檔包含頁面標題及其鏈接。您可以生成完整的導航,從每個頁面到任何其他頁面,以及到前一個和后一個頁面。這些細節不屬于本文的介紹范圍,但 參考資料 中提供了使用主文檔的 HTML 演示的鏈接??蓪?.xml 替換為 .html 來獲得編譯后的版本。讓瀏覽器向您顯示 .xml 的整潔源代碼。您會對它生成的源代碼量感到驚奇。
解釋與編譯的對比

  解釋意味著頁面為 XML 格式(其文件擴展名為 .xml,其內容類型為文本/xml 或應用程序/xml),并且處理指令所引用的 XSLT 樣式表可在瀏覽器中執行。

  編譯意味著瀏覽器看到的是 HTML(其文件擴展名為 .html,內容類型為文本/html),它是在請求頁面之前從您的開發環境中或服務器上的 XML 轉換而來的。Xalan 和 Saxon 都是著名的 XSLT 處理器。

  解釋是未來的發展方向。所有現代瀏覽器都支持 XSLT,并且它具有一些優點:

當測試時,您會立即獲得結果。只需在您測試的每個瀏覽器中按下 F5,即可反映源頁面、CSS 和 XSLT 樣式表的更改。
要傳遞給客戶端的信息量減少了。
客戶端看到的是一個干凈、整潔的網頁,因為還未生成擴充內容。

  但也要注意一些缺點:

有一些舊瀏覽器可能不支持 XSLT。如果向一個受控的環境(內部網)發布頁面,就不會出現問題。
一些現代瀏覽器禁止 XSLT 樣式表引用另一個目錄中的另一個樣式表。
將 XSLT 域其他功能相結合(比如 SVG 或 iframe)可能在一些瀏覽器中導致問題。
因為大部分瀏覽器都不支持 XSLT 2.0 或即將推出的 3.0,所以您無法使用新功能。沒有 XPath 2.0 if () then … else,也沒有用戶編寫的 XPath 功能。

  無論進行編譯還是解釋,頁面的其他轉換 (CSS、JavaScript) 都會在 XSLT 轉換之后執行。
結束語

  在本文中,您學習了如何使用 XSLT 樣式表來擴充 XHTML 文檔。您可以使用本文中的示例作為起點,構建您自己的 XSLT 樣式表。

 

 

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
亚洲香蕉成人av网站在线观看_欧美精品成人91久久久久久久_久久久久久久久久久亚洲_热久久视久久精品18亚洲精品_国产精自产拍久久久久久_亚洲色图国产精品_91精品国产网站_中文字幕欧美日韩精品_国产精品久久久久久亚洲调教_国产精品久久一区_性夜试看影院91社区_97在线观看视频国产_68精品久久久久久欧美_欧美精品在线观看_国产精品一区二区久久精品_欧美老女人bb
2019av中文字幕| 国产精品视频白浆免费视频| 欧美日韩国产丝袜另类| xxxxx91麻豆| 欧美激情国产高清| 国产a级全部精品| 亚洲综合精品伊人久久| 国产日韩欧美在线看| 992tv成人免费影院| 亚洲第一精品福利| 国产精品wwww| 成人中文字幕+乱码+中文字幕| 国产成人+综合亚洲+天堂| 懂色av影视一区二区三区| 美女撒尿一区二区三区| 日韩毛片在线看| 欧美精品免费播放| 欧美大片免费观看| 亚洲欧洲高清在线| 国产97在线亚洲| 精品国产成人av| 97久久伊人激情网| 97av在线视频免费播放| 日本精品久久久久影院| 欧美电影免费观看电视剧大全| 国产精品中文字幕在线观看| 亚洲视频欧洲视频| 97视频人免费观看| 国产成人一区二| 色中色综合影院手机版在线观看| 亚洲欧美成人一区二区在线电影| 国产日韩精品入口| 国产欧美日韩亚洲精品| 亚洲视频在线观看免费| 欧美日韩在线免费观看| 国产午夜精品免费一区二区三区| 国产精品69久久久久| 国产一区二区免费| 色妞久久福利网| 国产精品成人国产乱一区| 97在线观看视频国产| 2021国产精品视频| 全球成人中文在线| 欧美大尺度激情区在线播放| 亚洲性av在线| 亚洲午夜国产成人av电影男同| 精品国产乱码久久久久酒店| 最新的欧美黄色| 国产一区二区三区18| www.亚洲一区| 国产欧美一区二区三区久久| 日韩精品免费综合视频在线播放| 日韩电影视频免费| 国产999精品久久久影片官网| 中文字幕免费精品一区| 欧美丝袜一区二区| 欧美中文在线字幕| 国模精品系列视频| 在线免费观看羞羞视频一区二区| 日韩欧美在线第一页| 97成人在线视频| 韩剧1988在线观看免费完整版| 欧美激情欧美狂野欧美精品| 国产精品美女www爽爽爽视频| 亚洲福利精品在线| 成人黄色免费网站在线观看| 久久久久久69| 亚洲护士老师的毛茸茸最新章节| 狠狠久久亚洲欧美专区| 日韩电影在线观看免费| 亚洲第一网站免费视频| 国产精品久久在线观看| 久久久久久久91| 国产亚洲欧洲高清一区| 国产91在线播放九色快色| 亚洲欧美日韩另类| 91夜夜未满十八勿入爽爽影院| 亚洲成人网av| 久久精品免费电影| 国产午夜精品美女视频明星a级| 夜夜嗨av色一区二区不卡| 久色乳综合思思在线视频| 精品久久香蕉国产线看观看亚洲| 欧美片一区二区三区| 成人国产在线激情| 欧美综合在线观看| 日本一区二区三区四区视频| 亚洲精品久久久久中文字幕欢迎你| 国产精品偷伦视频免费观看国产| 国产乱人伦真实精品视频| 美女999久久久精品视频| 日韩成人在线视频网站| 在线视频日本亚洲性| 自拍偷拍亚洲区| 欧美极品欧美精品欧美视频| 美日韩精品免费视频| 成人免费看黄网站| 久久影院资源网| 欧美区在线播放| 欧美激情在线狂野欧美精品| 欧美精品制服第一页| 亚洲欧美制服第一页| 日韩av在线免费播放| 日韩欧美a级成人黄色| www亚洲欧美| 亚洲精品久久久久久久久| 国产一区二区成人| 国产精品无码专区在线观看| 久久久亚洲欧洲日产国码aⅴ| 精品欧美国产一区二区三区| 久久手机精品视频| 国产精品久久久久久久久久免费| www高清在线视频日韩欧美| 久久精品免费播放| 欧美xxxx综合视频| 91精品国产777在线观看| 久久久久五月天| 亚洲欧洲视频在线| 国产免费成人av| 国产成人短视频| 亚洲国产婷婷香蕉久久久久久| 国产中文字幕91| 日韩在线视频播放| 欧美综合激情网| 欧美激情精品久久久久久蜜臀| 色一区av在线| 国产经典一区二区| 九九热精品视频国产| 国产精品久久久久久久久久东京| 欧美日韩中文字幕在线视频| 日韩精品中文字幕在线观看| 亚洲日韩欧美视频| 日韩视频在线观看免费| 国产精品视频久久久| 欧美成aaa人片在线观看蜜臀| 欧美国产亚洲精品久久久8v| 精品在线欧美视频| 亚洲国产日韩欧美在线动漫| 中文字幕精品影院| 91久久精品国产| 亚洲视频axxx| 亚洲成人免费在线视频| 久久精品电影网站| 日韩精品999| 日韩在线www| 亚洲美女黄色片| 欧美精品在线视频观看| 久久不射热爱视频精品| 亚洲欧美中文字幕在线一区| 国产视频久久久| 国产精品扒开腿做| 亚洲国产精彩中文乱码av| 欧美丝袜第一区| 日韩精品中文字幕在线| 国产精品精品一区二区三区午夜版| 高清在线视频日韩欧美| 欧美小视频在线观看| 91精品久久久久久| 久久久久久国产精品| 91精品久久久久久久久中文字幕| 日韩在线视频网| 欧美性极品xxxx娇小| 欧美精品久久久久a| 中日韩美女免费视频网站在线观看|