I have an XML document that has a series of paragraphs:
<section>
<title>Section title</title>
<p style="Body">...</p>
<p style="Body">...</p>
<p style="Note">...</p>
<p style="Body">...</p>
<p style="Body">...</p>
<p style="Warning">...</p>
<p style="Warning">...</p>
<p style="Warning">...</p>
<p style="Body">...</p>
<p style="Note">...</p>
<p style="Note">...</p>
<p style="Warning">...</p>
<p style="Body">...</p>
</section>
I want to group some paragraphs so I can apply formatting to the entire group, e.g. put them inside a div so I can put a border around them. The order of the elements has to be preserved. The paragraphs I want to group have the @style 'Note','Warning' or 'Caution'. Specifically, I want to group them only if two or more paragraphs of the same @ style are adjacent to each other.
<section>
<title>Section title</title>
<p style="Body">...</p>
<p style="Body">...</p>
<p style="Note">...</p>
<p style="Body">...</p>
<p style="Body">...</p>
<div>
<p style="Warning">...</p>
<p style="Warning">...</p>
<p style="Warning">...</p>
</div>
<p style="Body">...</p>
<div>
<p style="Note">...</p>
<p style="Note">...</p>
</div>
<p style="Warning">...</p>
<p style="Body">...</p>
</section>
I'm having trouble with the for-each-group instruction:
<xsl:for-each-group select="*" group-adjacent="@stylename">
(wrap in div here)
This gives me an error because the title element does not have a @stylename attribute.
I can't do for-each-group select="p" because then the title element is not processed at all.
How do I process all elements in the section, but group only the paragraphs by their @stylename?
What error are you getting? I'm assuming it's something like:
This is because (from the spec):
Try changing:
to:
Example: