0
votes

I have a lot XML documents that contain <h1>text</h1> . for example :

<p>
 <h1>
   text-1
 </h1>
 a lot text
 <h1>
   text-2
 </h1>
</p>

I insert this code :

for $p in (1 to 351)
return <a href="{$p}">{data(doc(concat("/db/INDEX/",$p,".html"))//h1)}</a>

The result is This :

<a href="2"<----this is page number >
 text-1
 text-2
</a>
<a href="3"<----this is page number />

Notice: when in one page are two tag or more <h1> the texts show in one tag <a>

but i need this :

<a href="2">
 text-1
</a>
<a href="2">
 text-2
</a>

And when in a page are not <h1> tag , show empty <a>.

2
You will have to move some of the functionnality inside your XQUERY statement. What is the XSLT aspect of this? You used the tag but there does not seem to be an XSLT component in your solution. - Marcus Rickert
Please use tags that actually match your question (this isn't about XSLT at all) and make sure to select answers as accepted if they solved your question. Have a look at the FAQ. - Jens Erat

2 Answers

1
votes

How about:

for $h in collection("/db/INDEX")//h1
let $i := replace(document-uri(root($h)), ".*/(.*)\.html", "$1")
return
    <a href="{$i}">{string($h)}</a>
0
votes

Ok. i resolve :

xquery version "3.0";
for $P in 1 to 351
  let $S := data(doc(concat('/db/INDEX/' , $P , '.html'))//h1)
    for $result in $S
     return <a>{$result}</a>