2011-08-11 148 views
16

獲取當前節點的父節點名稱的正確語法是什麼?我知道它是關於AxisName的父類,但是什麼是正確的語法? 例如下面的XML如何獲取當前節點的父節點名稱?

<netcdf xmlns="http://www.unidata.ucar.edu/namespaces/netcdf/ncml-2.2" location="file:/dev/null" iosp="lasp.tss.iosp.ValueGeneratorIOSP" start="0" increment="1"> 
    <attribute name="title" value="Vector time series"/> 
    <dimension name="time" length="100"/> 
    <variable name="time" shape="time" type="double"> 
     <attribute name="units" type="String" value="seconds since 1970-01-01T00:00"/> 
    </variable> 
    <group name="Vector" tsdsType="Structure" shape="time"> 
     <variable name="x" shape="time" type="double"/> 
     <variable name="y" shape="time" type="double"/> 
     <variable name="z" shape="time" type="double"/> 
    </group> 
</netcdf> 

爲元素可變我應該得到的NetCDF或基團。提前致謝。

+1

好問題,+1。查看我的答案,獲取最短可能的XPath表達式,該表達式的計算結果爲當前節點的父節點的名稱。也是爲什麼父母可能沒有名字的解釋。最後,這真的是一個XPath問題,而不是XSLT問題。 –

回答

8

name(parent::*)應該這樣做。顯然,只有一位家長。

29

使用

name(..) 

..縮寫是parent::node()的簡寫。

做筆記:不是每個父母都有一個名字。例如,文檔節點(/)是文檔的頂層元素(/*)的父級,並且沒有名稱。

+0

使用它作爲retrive父名稱在我的情況驅動器出來內存錯誤,而不是使用名稱(parent :: *) –

+0

@CarlosCocom,這隻能表明你正在使用的特定XPath實現是越野車。如果您可以提供一個XML文檔(最好是非常短的)和精確的XPath表達式,那將會很有趣。 –

相關問題