I want to change the values of the @page
attributes of <line/>
that are descendants of <section type="cover"/>
to (max(@page) + 1)
of <section type="contents"/>
.
Basically I need the page number for the cover section to be 1 higher than the last numeric page number of the contents section.
Note: <line/>
nodes are not always siblings, they can be nested at any level.
For example transform this:
<root>
<section type="contents">
<line page="i">text</line>
<line page="ii">text</line>
<line page="1">text</line>
<line page="1">text</line>
<line page="2">text</line>
<block>
<line page="3">text</line>
<line page="4">text</line>
</block>
</section>
<section type="cover">
<line page="i">text</line>
<line page="i">text</line>
</section>
</root>
to this:
<root>
<section type="contents">
<line page="i">text</line>
<line page="ii">text</line>
<line page="1">text</line>
<line page="1">text</line>
<line page="2">text</line>
<block>
<line page="3">text</line>
<line page="4">text</line>
</block>
</section>
<section type="cover">
<line page="5">text</line> <!-- @page changes to max()+1 -->
<line page="5">text</line> <!-- @page changes to max()+1 -->
</section>
</root>
Is there an easy way to achieve this with PHP5, XSLT1.0, XPATH?