我正在尝试选择父节点之前的 <li> 祖先节点的值。这是文档的示例,im-trg.xml:
<trg>
<category>
<h2>Accounting and Auditing</h2>
<ul>
<li>Laws and Regulations
<ul>
<li><a href="url1">Regulation S-X</a></li>
</ul>
</li>
<li>Staff Guidance
<ul>
<li>No Action Letters
<ul>
<li><a href="url2">Robert Van Grover, Esq., Seward and Kissel LLP</a> (November 5, 2013)</li>
</ul>
</li>
</ul>
</li>
</ul>
</category>
</trg>
这是我的查询:
for $x in doc("C:\im-trg.xml")//li/a
return
<item>
<title>{data($x)}</title>
<documentType>{data($x/ancestor::li[2])}</documentType>
<category>{data($x/ancestor::category/h2)}</category>
</item>
我正进入(状态:
<item>
<title>Regulation S-X</title>
<documentType>Laws and RegulationsRegulation S-X</documentType>
<category>Accounting and Auditing</category>
</item>
对于 <documentType>,我只想选择 <a> 的 <li> 父级之前的祖先 <li>,它指示文档的类型,所以我想要:
<item>
<title>Regulation S-X</title>
<documentType>Laws and Regulations</documentType>
<category>Accounting and Auditing</category>
</item>
和
<item>
<title>Robert Van Grover, Esq., Seward and Kissel LLP</title>
<documentType>No Action Letters</documentType>
<category>Accounting and Auditing</category>
</item>
我不认为我可以从根上下来,因为父 <li> 有时是双重嵌套的,有时是三重嵌套的。