共用方式為


current 函式

傳回含有目前節點的節點集做為其唯一的成員。

node-set current()

備註

此函式會傳回含有目前節點的節點集做為其唯一的成員。對於最外層的運算式 (不在其他運算式中發生的運算式) 而言,目前節點永遠與內容節點相同。因此,

<xsl:value-of select="current()"/>

等同於

<xsl:value-of select="."/>

但在方括號內,目前節點通常與內容節點不同。例如:

<xsl:apply-templates select="//glossary/item[@name=current()/@ref]"/>

處理具有 <glossary> 父項目、且 name 屬性值與目前節點的 ref 屬性值相同的所有 <item> 項目。這不同於

<xsl:apply-templates select="//glossary/item[@name=./@ref]"/>

其意義等同於

<xsl:apply-templates select="//glossary/item[@name=@ref]"/>

因此會處理具有 <glossary> 父項目、且 name 屬性值與 ref 屬性值相同的所有 <item> 項目。

範例

XML 檔 (current.xml)

<?xml version='1.0'?>
<?xml-stylesheet type="text/xsl" href="current.xsl" ?>
<nodes>
   <node>first</node>
   <node>1</node>
   <node>
      <obj>class</obj>
   </node>
</nodes>

XSLT 檔 (current.xsl)

<?xml version='1.0'?>
<xsl:stylesheet version="1.0"
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">
  <xsl:apply-templates/>
</xsl:template>

<xsl:template match="text()">
  <xsl:value-of select="current()"/>
</xsl:template>

<xsl:template match="*">
  <blockquote><xsl:apply-templates/></blockquote>
</xsl:template>

</xsl:stylesheet>

輸出

以下是瀏覽器中所顯示的格式化輸出。

first

1

class

以下是 XSLT 處理器的輸出。若要取得此輸出,請在瀏覽器上按一下滑鼠右鍵,然後選取 View XSL Output 功能表項目。

<?xml version="1.0" encoding="UTF-16"?>
<blockquote>
   <blockquote>first</blockquote>
   <blockquote>1</blockquote>
   <blockquote>
      <blockquote>class</blockquote>
   </blockquote>
</blockquote>

請參閱

參考

XML 資料型別參考