欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

跟我學XSL(二)

 更新時間:2006年10月16日 00:00:00   作者:  

本期介紹多個XSL對于VBScript、JScript增加的方法、屬性,以充分發(fā)揮XML的優(yōu)勢,用于<xsl:script>、<xsl:eval>標記內(nèi)表達式的編寫或<xsl:if>、<xsl:when>的expr屬性。

  一、absoluteChildNumber

  含義:返回結點相對于它所有的兄弟(不論名字是否相同)的序號。

  語法:absoluteChildNumber(node)

  參數(shù):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

  含義:從給定結點出發(fā)根據(jù)給定祖先結點名返回最近的祖先結點的序號(相對于同名結點)。如果找不祖先,則返回0。

  語法:ancestorChildNumber(bstrNodeName, pNode)

  參數(shù):

  bstrNodeName ── 字符串。被搜索的祖先結點的名字。

  pNode ── 對象。搜索開始位置的結點。

  示例查找當前結點最近的名為report祖先結點:

ancestorChildNumber('report',this)

  三、attributes

  含義:返回結點屬性的集合。

  語法:object.attributes

  參數(shù):object ── 結點對象。

  示例:當前結點屬性的個數(shù)

this.attributes.length

  當前結點第三個屬性的值

this.attributs.item(2).value



this.attributes.item(2).text



this.attributes(2).text

  注意:如果給定的下標大于屬性總和減1將出錯,第一個屬性的下標是0。

  四、baseName

  含義:返回有名字空間限制的基本名,即不包括名字前綴。

  語法:object.baseName

  參數(shù):object ── 結點對象

  示例,當前結點的基本名:

this.baseName

  五、childNumber

  含義:返回結點相對于同名同胞的序號。

  語法:childNumber(object)

  參數(shù):object ── 結點對象

  示例,假定XML文檔結構如下:

<x><y><z></z></y></x>

  如果當前結點是z,則childNumber(this)返回1,而absoluteChildNumber(this)返回3。

  六、dataType

  含義:設定或讀取結點的數(shù)據(jù)類型。

  語法:設定結點的數(shù)據(jù)類型 object.dataType=objValue
     讀取結點的數(shù)據(jù)類型 objValue=object.dataType

  參數(shù):object ── 結點對象。

  示例,讀取當前結點的數(shù)據(jù)類型:

dtType=this.dataType

  七、depth

  含義:指定結點出現(xiàn)在文檔樹上的深度,即該結點位于文檔第幾層,頂層結點位于第一層,根結點(即用"/"表示的結點)位于第0層。

  語法:depth(pNode)

  參數(shù):pNode ── 結點對象

  示例,當前結點的深度:

depth(this)

  八、firstChild、lastChild

  含義:返回結點的第一個子結點(或最后一個子結點)。

  語法:pNode.firstChild
     pNode.lastChild

  參數(shù):pNode ── 結點對象

  示例,當前結點的第一個結點的名字:

this.firstChild.nodeName

  九、formatIndex

  含義:用指定的計數(shù)系統(tǒng)格式化提供的整數(shù)。

  語法:formatIndex(lIndex, bstrFormat)

  參數(shù):

  lIndex ── 整型數(shù)值或變量

  bstrFormat ── 數(shù)據(jù)格式,可選值有a、A、i、I、1、01(以0打頭的數(shù)值形式,如果要求固定長度的編號如0001、0002則非常有用)。

  示例,當前結點的大寫羅馬數(shù)字編號:

formatIndex(childNumber(this),'I')

  十、formatNumber

  含義:以指定格式輸出數(shù)值。

  語法:formatNumber(dblNumber, bstrFormat)

  參數(shù):說明同formatNumber,不同之處在于格式化的可以是小數(shù)。

  示例,對變量a的值格式化為兩位小數(shù):

formatNumber(a,'#.00'):

  十一、hasChildNodes

  含義:如果結點有子結點則返回true(-1),否則為false(0)。

  語法:pNode.hasChildNodes()

  注意:與此前介紹的函數(shù)不同,此函數(shù)后必須帶一個空括號。

  示例,判斷當前結點是否有子結點:

this.hasChildNodes

  十二、namespaceURI、prefix

  含義:返回結點名字空間的全局資源標識符(或前綴)。

  語法:pNode.namespaceURI
     pNode.prifix

  十三、nextSibling、previousSibling、parentNode

  含義:返回結點的下一個兄弟(或前一個兄弟、或結點的父結點)。

  語法:pNode.nextSibling
     pNode.previousSibling
     pNode.parentNode

  注意:對根結點(即"/")應用parentNode方法、對第一個孩子結點應用previousSibling方法、對最后一個孩子結點應用nextSibling方法均會導致錯誤,可通過此過關系運算符==(等于)和!=(不等于)來判斷一個結點是否某一指定結點,格式為pNode1 = pNode2或pNode2 != pNode2。

  十四、nodeName

  含義:返回元素、屬性、入口的名字或其他類型結點的一個特定字符串。

  語法:pNode.nodeName

  示例,當前結點的名字:

this.nodeName

  十五、nodeType、NodeTypeString

  含義:返回結點的類型的數(shù)值形式(或字符串形式)。

  語法:pNode.nodeType 或 pNode.nodeTypeString

  返回值:

 結點類型  結點類型值  結點的字符形式描述
 Element  1  'element'
 Element Attribute  2  'attribute'
 Markup-Delimited Region of Text  3  'text'
 Processing Instruction  7  'processing_instruction'
 Comment  8  'comment'
 Document Entity  9  'document'

  十六、nodeTypedValue

  含義:以結點預定義的數(shù)據(jù)類型返回結點的值。

  語法:pNode.nodeTypedValue

  示例,假定當前結點的數(shù)據(jù)類型是fixed.14.4,下例將以數(shù)值返回結點的值,而不是文本一個字符串:

this.nodeTypedValue

  十七、nodeValue

  含義:返回結點的文本。

  語法:pNode.nodeValue

  注意:該方法不用于元素類結點,可用于屬性、CDATA、注釋、文本等結點。

  示例,當前元素第一個屬性的值:

this.attributes(0).nodeValue

  當前元素內(nèi)的文本(假定該元素內(nèi)只有文本,無其它元素,即<mark>text</mark>,建議多嘗幾次掌握其確切的用法)。

this.firstChild.nodeValue

  十八、ownerDocument

  含義:返回包含該結點的文檔的根。

  語法:pNode.ownerDocument

  注意:該方法用于文檔的根結點將出錯。

  十九、selectNodes

  含義:給定的樣式匹配應用于當前結點并返回匹配的結點集合。

  語法:pNode.selectNodes('pattern')

  提示:pattern的編寫與<xsl:for-each>的select屬性的值類似,其中以"/"開頭表示從文檔的根出發(fā)搜索;以"http://"開頭表遍歷文檔的所有結點;以".."開頭表示從當前結點的父結點開始;如果欲從當前結點向下搜索則不能有以上特殊字符打頭。

  示例,與當前結點同名的元素在其父元素內(nèi)的個數(shù):

childNumber(this.selectNodes("../"+this.nodeName+"[end()]").item(0))

  當前元素內(nèi)名字為"skill"的元素的個數(shù):

childNumber(this.selectNodes("skill[end()]").item(0))

  二十、selectSingleNode

  含義:與selectNodes類似,不同的只返回匹配的第一個結點、而不是結點集合。

  語法:pNode.selectSingleNode('pattern')

  示例,與當前結點同名的元素在其父元素內(nèi)的個數(shù):

childNumber(this.selectSingleNode("../"+this.nodeName+"[end()]"))

  當前元素內(nèi)名字為"skill"的元素的個數(shù):

childNumber(this.selectSingleNode("skill[end()]"))

  二十一、text

  含義:返回結點與它的子樹內(nèi)的文字內(nèi)容。

  語法:pNode.text

  示例,整個文檔內(nèi)的文字內(nèi)容:

this.ownerDocument.text

  當前元素及其子樹的文字內(nèi)容:

this.text

  二十二、xml

  含義:返回結點及其后代的XML表示。

  語法:pNode.xml

  示例,當前文檔的XML內(nèi)容:

this.ownerDocument.xml

  另有幾個函數(shù)不作介紹,列于其下以供參考,如感興趣,請訪問http://msdn.microsoft.com獲取詳細說明。

formatTime(varTime, bstrFormat,varDestLocale)
formatDate(varDate, bstrFormat,varDestLocale)
apendChild(newChild)
definition
CloneNode
insertBefore(newChild, refChild)
parsed
removeChild(oldChild)
replaceChild(newChild, oldChild)
specified
transformNode(stylesheet)
transformNodeToObject(stylesheet,outputObject)
uniqueID(pNode)

相關文章

最新評論