The logic you are using does not apply to a functional programming language like XQuery. I guess you want to iterate over each h1
element and want to include an increasing counter. This is actually even simpler than you probably imagined:
for $result at $key in data(doc(concat('/db/INDEX/' , $P , '.html'))//h1)
return <a class="libraryIndexlink" href="http://library.net/newindex.aspx?pid=102834&BookID=106201&PageIndex={$P}&Language=1#p{$key - 1}">{$result}</a>
The at $key
statement gives you the position, i.e. the counter you want. As it seems you want to start with 0, but in XQuery sequences always start at position 1, hence we use the - 1
There are a couple of other things wrong in your code. You will have to put XQuery function calls or variables into curly braces, what you did do for $P
, but not for local:prod2ndDigit()
.
That the code let $C := 0 return $C = $C + 1
returns false
is correct. You are using the =
operator, which does mean equal in XQuery. You probably intended to write an assignment, which the operator for is :=
. Also, it seems like you want to increase the counter. Keep in mind that XQuery is a functional language, as I said before, so you can never manipulate a variable You will always create a new $counter
variable and shadow the old value, but you can not change the variable as you do in other languages like C, Java, Python and so on and so forth.
I don't have any idea what you want to achieve with your function local:prod2ndDigit()
. It returns a sequence of items, but I do not see the use case here.