本期介紹多個XSL對於VBScript、JScript增加的方法、屬性,以充分發揮XML的優勢,用於< xsl:script >、< xsl:eval >標記內運算式的編寫或< xsl:if >、< xsl:when >的expr屬性。
一、absoluteChildNumber
含義:返回結點相對於它所有的兄弟(不論名字是否相同)的序號
文法:absoluteChildNumber(node)
參數:node ── 對象,欲返回編號的結點。
樣本:
1、假定文檔結構為:< document >< head/ >< body/ >< /document >,其中document為頂層結點,下述運算式將輸出
< xsl:eval >
absoluteChildNumber(this.selectNodes("/document/body").item(0))
< /xsl:eval >
2、確定當前結點相對於其所有兄弟的序號
< xsl:eval >absoluteChildNumber(this)< /xsl:eval >
二、ancestorChildNumber
含義:從給定結點出髮根據給定祖先結點名返回最近的祖先結點的序號(相對於同名結點)。如果找不祖先,則返回0。
文法:ancestorChildNumber(bstrNodeName, pNode)
參數:
bstrNodeName ── 字串。被搜尋的祖先結點的名字。
pNode ── 對象。搜尋開始位置的結點。
樣本:
尋找當前結點最近的名為report祖先結點。
ancestorChildNumber("report",this)
三、attributes
含義:返回結點屬性的集合
文法:object.attributes
參數:object ── 結點對象
樣本:
當前結點屬性的個數
this.attributes.length
當前結點第三個屬性的值
this.attributs.item(2).value
或this.attributes.item(2).text
或this.attributes(2).text
注意:如果給定的下標大於屬性總和減1將出錯,第一個屬性的下標是0。
四、baseName
含義:返回有名字空間限制的基本名,即不包括名字首碼
文法:object.baseName
參數:object ── 結點對象
樣本:當前結點的基本名:this.baseName
五、childNumber
含義:返回結點相對於同名同胞的序號
文法:childNumber(object)
參數:object ─? 岬愣韻?/p>
樣本:假定XML文檔結構如下
< x >< y >< z >< z/ >< y/ >< /x >
如果當前結點是z ,則childNumber(this)返回1,而absoluteChildNumber(this)返回3。