2011-08-11 151 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表达式,那将会很有趣。 –

相关问题