【发布时间】:2017-09-13 16:34:19
【问题描述】:
我正在尝试仅提取具有特定类型 <xref> 类型并使用 Xquery 匹配特定外部参照列表的 <book> 数据(我是新手)。
这是输入数据:
<book id="6636551">
<master_information>
<book_xref>
<xref type="Fiction" type_id="1">72771KAM3</xref>
<xref type="Non_Fiction" type_id="2">US72771KAM36</xref>
</book_xref>
</master_information>
</book>
<book id="119818569">
<master_information>
<book_xref>
<xref type="Fiction" type_id="1">070185UL5</xref>
<xref type="Non_Fiction" type_id="2">US070185UL50</xref>
</book_xref>
</master_information>
</book>
<book id="119818568">
<master_information>
<book_xref>
<xref type="Fiction" type_id="1">070185UK7</xref>
<xref type="Non_Fiction" type_id="2">US070185UK77</xref>
</book_xref>
</master_information>
</book>
<book id="119818567">
<master_information>
<book_xref>
<xref type="Fiction" type_id="1">070185UJ0</xref>
<xref type="Non_Fiction" type_id="2">US070185UJ05</xref>
</book_xref>
</master_information>
</book>
<book id="38085123">
<master_information>
<book_xref>
<xref type="Fiction" type_id="1">389646AV2</xref>
<xref type="Non_Fiction" type_id="2">US389646AV26</xref>
</book_xref>
</master_information>
</book>
我正在使用的 XQuery:
for $x in //book
where $x//xref/@type='Fiction'
and
$x//xref=('070185UL5','070185UJ0')
return $x
上面的 Xquery 只获取匹配“070185UL5”的第一本书信息。我希望它能够同时获取两者。怎么了?感谢您的回复。
【问题讨论】:
-
它确实获取了两者。
-
对我来说看起来不错,并且在使用 Saxon 进行测试时可以正常工作。也许尝试将您的 where 子句更改为
where $x//xref[@type='Fiction'][normalize-space()=('070185UL5','070185UJ0')]。 -
对不起。当我现在再次尝试时,它确实获取了两者。我不知道为什么它以前不起作用。感谢您的宝贵时间!