0

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>.

Jens Erat
  • 37,523
  • 16
  • 80
  • 96
A.A
  • 1,138
  • 1
  • 16
  • 29
  • 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 Apr 20 '14 at 12:35
  • 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 Apr 21 '14 at 13:55

2 Answers2

1

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>
adamretter
  • 3,885
  • 2
  • 23
  • 43
0

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>
A.A
  • 1,138
  • 1
  • 16
  • 29