The most recent successful query I ran was this one:
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>
)
But it seems it’s structured incorrectly because I receive 2 results in the second div rather than two seller_rating-classed div’s with one result per each. Looking at the code, it makes sense that I get these results. Trying to restructure the query, I’m perplexed. Here’s my progress:
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>
The xml file being:
<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>
I can’t help but feel that this is the wrong way to structure the query because when I don’t believe that the results can be ordered well/without the addition of a further-complex structure. If anyone is able to understand the desired output, please help me restructure my query.
Current output:
<div>6356</div><div>C31T150 hr.</div>
Desired output:
<div class="seller_company_id">6356</div>
<div class="seller_rating">C31</div>
<div class="seller_rating">T150 hr.</div>
Please poste valid code. There are lots of syntax errors in there! Code not accepted by the compiler is very bad style and doesn’t show you’re trying hard to fix the problems yourself. If you don’t know what the problem is, build a shorter example and try to fix it again, if you really don’t get it ask a question here.
"afterseller_company_idThis nearly does what you want, I didn’t change
idtoclass. I removed some of thelet-clauses, add them again if you think it’s more readable for you.