M
MRe
Hi,
Is it possible using XSLT to transform this..
<test>
<b>0</b>
<a>1</a>
<a>2</a>
<b>3</b>
<b>4</b>
5
<b>6</b>
<b>7</b>
<b>8</b>
</test>
..into this (it's basically just wrapping groups of <b>s in a <c>)..
<test>
<c>
<b>0</b>
</c>
<a>1</a>
<a>2</a>
<c>
<b>3</b>
<b>4</b>
</c>
5
<c>
<b>6</b>
<b>7</b>
<b>8</b>
</c>
</test>
..that is, treat, in a mix of nodes, a specified group of nodes
(nodes that appear one-after-the-other, having no node outside that
group (except ignored empty text() nodes) between them) as a block?
(in the example above, <b> is the only chosen node in this group)
The closest I've come to getting this is to call a recursive
template, passing child::*[1] initially, and following-sibling::*[1]
for each recursive step, and also passing a 'block' parameter that, if
false and <b> is encountered, puts a <c> in and sets block to true,
and if true and <a> is encountered, puts a </c> in and sets to false.
However, this won't work as it won't put a </c> in if the last element
is a <b>.
All other attempts I've made at a solution I'd prefer to keep to
myself [embarrassed]
Thank you,
Kind regards,
Eliott
Is it possible using XSLT to transform this..
<test>
<b>0</b>
<a>1</a>
<a>2</a>
<b>3</b>
<b>4</b>
5
<b>6</b>
<b>7</b>
<b>8</b>
</test>
..into this (it's basically just wrapping groups of <b>s in a <c>)..
<test>
<c>
<b>0</b>
</c>
<a>1</a>
<a>2</a>
<c>
<b>3</b>
<b>4</b>
</c>
5
<c>
<b>6</b>
<b>7</b>
<b>8</b>
</c>
</test>
..that is, treat, in a mix of nodes, a specified group of nodes
(nodes that appear one-after-the-other, having no node outside that
group (except ignored empty text() nodes) between them) as a block?
(in the example above, <b> is the only chosen node in this group)
The closest I've come to getting this is to call a recursive
template, passing child::*[1] initially, and following-sibling::*[1]
for each recursive step, and also passing a 'block' parameter that, if
false and <b> is encountered, puts a <c> in and sets block to true,
and if true and <a> is encountered, puts a </c> in and sets to false.
However, this won't work as it won't put a </c> in if the last element
is a <b>.
All other attempts I've made at a solution I'd prefer to keep to
myself [embarrassed]
Thank you,
Kind regards,
Eliott