xmlxpathxpath-3.0

Divide a set of items XPath


I am new to XPath so do not know much. I have been googling for a bit and cannot find anything, maybe I am just searching the wrong thing but I thought I would ask on here.

I am currently trying to divide a set of numbers, (100, 200, 300), all by the same value. So I want: 100/2, 200/2, 300/2. I initially assumed it would be something like: //products/price div 2, but this would try and divide the actual set itself by 2 instead of the items

How would I go about doing this? Thanks


Solution

  • XPath 3.0 has for expressions:

    for $n in (100, 200, 300) return $n div 2
    

    returns a sequence of

    (50, 100, 150)
    

    as requested.