我最近运行的成功查询是这个:
let $doc := doc('test')
for $v in $doc//item
where $v/product_info/unit[.='9291']
return (
<div class="seller_company">{ $v/seller_info/seller_company_id[position() lt 2]/text() }
</div>,
<div class="seller_rating">{ $v/seller_info/seller_rating[position() lt 3]/text() }
</div>
)
但似乎它的结构不正确,因为我在第二个 div 中收到 2 个结果,而不是在两个 Seller_rating-classed div 中,每个 div 有一个结果。查看代码,我得到这些结果是有道理的。试图重组查询,我很困惑。这是我的进展:
let $doc := doc('test')//item
for $v in $doc
where $v/product_info/unit[.='9291']
let $x := return $v/seller_info/seller_company_id,
$y := return $v/seller_info/seller_rating
for $resultx in $x/text()
return
<div id="seller_company_id>{ $resultx }</div>
for $resulty in $y/text()
return
<div id="seller_rating">{ $resulty }</div>
xml文件是:
<item>
<item_number>1171270</item_number>
<seller_info>
<seller_company_id>6356</seller_company_id>
<seller_rating>C31</seller_rating>
<seller_rating>T150 hr.</seller_rating>
</seller_info>
<product_info>
<unit>2022</unit>
<sinfo>55 cases</sinfo>
<sinfo>Yu-gi-oh trading card pack</sinfo>
<sinfo>.45kg per unit</sinfo>
<sinfo>24.7500kg shipment</sinfo>
</product_info>
<product_info>
<unit>9291</unit>
<sinfo>7 units</sinfo>
<sinfo>Naruto, Classic, action figure</sinfo>
<sinfo>1.8kg per unit</sinfo>
<sinfo>12.6kg shipment</sinfo>
</product_info>
</item>
我不禁觉得这是构造查询的错误方法,因为当我不相信结果可以很好地排序/不添加更复杂的结构时。如果有人能够理解所需的输出,请帮助我重组我的查询。
电流输出:
<div>6356</div><div>C31T150 hr.</div>
期望的输出:
<div class="seller_company_id">6356</div>
<div class="seller_rating">C31</div>
<div class="seller_rating">T150 hr.</div>