xpathxpath-3.1

How to get an attribute as an integer >= 1 with XPath?


Consider this input:

<tr>
   <td                  />
   <td rowspan="3"      />
   <td rowspan="-2"     />
   <td rowspan="*8#%@!" />
   <td rowspan="5.7"    />
   <td rowspan="-4.3"   />
   <td rowspan="6e1"    />
</tr>

From which I would like to get the rowspan attribute of every td node as an integer >= 1.

The resulting sequence should be:

1
3
1
1
5
1
60

Solution

  • A possibility is to use the filter [number() = number()] to only select values that are numerical:

    //td/( (1, @rowspan[number() = number()]) => max() => xs:integer() )