【发布时间】:2014-10-01 12:08:32
【问题描述】:
我有一个 XPath 2.0 查询(看起来没问题,它返回我希望它返回的节点),但是我需要用 XPath 1.0 编写它。有可能吗?如果可以,我该怎么做?
信息:
我想要做的是将IDENTIFIER 和qualifiedIdentifier 下面的所有tokenValue 节点的tokenValue 连接起来,如果这种连接导致一个以“another.pkg”开头的字符串,则选择qualifiedIdentifier 节点”。
XPath 2.0 查询:
//importDeclaration/qualifiedIdentifier[starts-with(string-join(descendant::*/*/@tokenValue,''),'another.pkg')]
xml:
<compilationUnit tokenValue="package" tokenLine="1" tokenColumn="0">
<packageDeclaration tokenValue="package" tokenLine="1" tokenColumn="0">
<PACKAGE tokenValue="package" tokenLine="1" tokenColumn="0">
<TOKEN tokenValue="package" tokenLine="1" tokenColumn="0"/>
</PACKAGE>
<qualifiedIdentifier tokenValue="my" tokenLine="1" tokenColumn="8">
<IDENTIFIER tokenValue="my" tokenLine="1" tokenColumn="8">
<TOKEN tokenValue="my" tokenLine="1" tokenColumn="8"/>
</IDENTIFIER>
<DOT tokenValue="." tokenLine="1" tokenColumn="10">
<TOKEN tokenValue="." tokenLine="1" tokenColumn="10"/>
</DOT>
<IDENTIFIER tokenValue="pkg" tokenLine="1" tokenColumn="11">
<TOKEN tokenValue="pkg" tokenLine="1" tokenColumn="11"/>
</IDENTIFIER>
</qualifiedIdentifier>
<SEMI tokenValue=";" tokenLine="1" tokenColumn="14">
<TOKEN tokenValue=";" tokenLine="1" tokenColumn="14"/>
</SEMI>
</packageDeclaration>
<importDeclaration tokenValue="import" tokenLine="3" tokenColumn="0">
<IMPORT tokenValue="import" tokenLine="3" tokenColumn="0">
<TOKEN tokenValue="import" tokenLine="3" tokenColumn="0"/>
</IMPORT>
<qualifiedIdentifier tokenValue="another" tokenLine="3" tokenColumn="7">
<IDENTIFIER tokenValue="another" tokenLine="3" tokenColumn="7">
<TOKEN tokenValue="another" tokenLine="3" tokenColumn="7"/>
</IDENTIFIER>
<DOT tokenValue="." tokenLine="3" tokenColumn="14">
<TOKEN tokenValue="." tokenLine="3" tokenColumn="14"/>
</DOT>
<IDENTIFIER tokenValue="pkg" tokenLine="3" tokenColumn="15">
<TOKEN tokenValue="pkg" tokenLine="3" tokenColumn="15"/>
</IDENTIFIER>
<DOT tokenValue="." tokenLine="3" tokenColumn="18">
<TOKEN tokenValue="." tokenLine="3" tokenColumn="18"/>
</DOT>
<IDENTIFIER tokenValue="AnotherClass" tokenLine="3" tokenColumn="19">
<TOKEN tokenValue="AnotherClass" tokenLine="3" tokenColumn="19"/>
</IDENTIFIER>
</qualifiedIdentifier>
<SEMI tokenValue=";" tokenLine="3" tokenColumn="31">
<TOKEN tokenValue=";" tokenLine="3" tokenColumn="31"/>
</SEMI>
</importDeclaration>
<typeDeclaration tokenValue="public" tokenLine="5" tokenColumn="0">
<modifier tokenValue="public" tokenLine="5" tokenColumn="0">
<PUBLIC tokenValue="public" tokenLine="5" tokenColumn="0">
<TOKEN tokenValue="public" tokenLine="5" tokenColumn="0"/>
</PUBLIC>
</modifier>
<classDeclaration tokenValue="class" tokenLine="5" tokenColumn="7">
<CLASS tokenValue="class" tokenLine="5" tokenColumn="7">
<TOKEN tokenValue="class" tokenLine="5" tokenColumn="7"/>
</CLASS>
<IDENTIFIER tokenValue="AClass" tokenLine="5" tokenColumn="13">
<TOKEN tokenValue="AClass" tokenLine="5" tokenColumn="13"/>
</IDENTIFIER>
<classBody tokenValue="{" tokenLine="5" tokenColumn="20">
<LWING tokenValue="{" tokenLine="5" tokenColumn="20">
<TOKEN tokenValue="{" tokenLine="5" tokenColumn="20"/>
</LWING>
<RWING tokenValue="}" tokenLine="6" tokenColumn="0">
<TOKEN tokenValue="}" tokenLine="6" tokenColumn="0"/>
</RWING>
</classBody>
</classDeclaration>
</typeDeclaration>
<EOF tokenValue="" tokenLine="6" tokenColumn="1"/>
</compilationUnit>
提前谢谢你!
【问题讨论】: