获取元素的XPath列表

我有具有特定名称的元素的NodeList,我想拥有所有theese节点的XPath。

我找不到如何做到这一点的方法。

NodeList nList = doc.getElementsByTagName("definition"); for (int i = 0; i < nList.getLength(); i++) { Node node = nList.item(i); System.out.println(node.GET_XPATH()); } 

我正在寻找像GET_XPATH()这样的方法

有人知道怎么做吗? 或者甚至可能吗?

如果有可能,XSLT也可以使用它,但更喜欢有人知道Java中的这种可能性。

原因:我需要一组指向XML库的指针。 用于定义元素的指针。

示例输入:

  
experiment Experiment

输出:

 /odML/section/definition /odML/section/property[1]/definition /odML/section/property[2]/definition /odML/section/property[2]/value/definition /odML/definition 

以下样式表:

XSLT 1.0

       /   [  ]   /definition  
     

当应用于您的示例输入时,将返回:

 /odML/section/definition /odML/section/property[1]/definition /odML/section/property[2]/definition /odML/section/property[2]/value/definition /odML/definition 

这种转变

     
          

应用于提供的源XML文档时

  
experiment Experiment

产生想要的,正确的结果

 /odML/section/definition /odML/section/property[1]/definition /odML/section/property[2]/definition /odML/section/property[2]/value/definition /odML/definition