xslt 2.0 - grouping following-siblings with same name and same attributes causes exception in saxon -



xslt 2.0 - grouping following-siblings with same name and same attributes causes exception in saxon -

i have xml documents (similar docbook) have transformed xsl-fo. of documents contains poems, , lines of poems written in separate p tags. verses separated br tags. there "page" tags irrelevant , should ignored.

typical code example:

<h4>headline</h4> <p>1st line of 1st verse</p> <p>2nd line of 1st verse</p> <br/> <p>1st line of 2nd verse</p> <p>2nd line of 2nd verse</p> <page n="100"/> <p>3rd line of 2nd verse</p> <h4>other headline</h4>

for xsl-fo output, gather text of verse 1 single fo:block. right mechanism works code structures above, there exceptions. actual way of doing decide every p tag: - first line of verse? - if yes: collect text of verse ynd write fo:block, utilize attributes of actual (first) p tag set formatting of block - if no: contents treated ealrier, nothing.

a first line p tag preceded h4 or br tag (or page tag preceded br tag). 1 easy develop.

collecting text of verse easy given example: grouping next siblings, defining groups ends h4 or br tags, take first grouping , utilize p tags (ignore in between page tags or ending h4 or br tag).

in code:

<xsl:for-each-group select="following-sibling::*" group-ending-with="br|h4"> <xsl:if test="position()=1"> <xsl:for-each select="current-group()[not(self::h4) , not(self::br) , not(self::page)]"> <xsl:apply-templates/>&crt; </xsl:for-each> </xsl:if> </xsl:for-each-group>

now similar code example:

<h4>headline</h4> <p class="center">1</p> <p>1st line of 1st verse</p> <p>2nd line of 1st verse</p> <br/> <p class="center">2</p> <p>1st line of 2nd verse</p> <p>2nd line of 2nd verse</p> <page n="100"/> <p>3rd line of 2nd verse</p> <h4>other headline</h4>

now centered p subheadlines next verses. not verse, purposes plenty if separated real verse's text. varied rule getting text of current verse is: grouping next siblings, defining groups ends h4 or br tags or p tag has class current p tag , take first grouping , utilize p tags (ignore in between page tags or ending h4 or br tag).

therefore stored value of class attribute of current p tag in variable called attributes , defined the grouping rule as:

<xsl:for-each-group select="following-sibling::*" group-ending-with="br|h4|p[normalize-space(@class) != $attributes]">

in eturn, when trying determine if p tag first line of verse, cannot preceded h4 or br, p tag has different class attribute value.

now works fine in testing environment in oxygen using saxon-b9.1.0.6. transformation has performed in java using saxon9.jar, , there usage of variable within group-ending-with attribute of xsl:for-each-group causes exception.

and kind of stuck.

could grouping conditions defined in improve way? or should maybe not done grouping @ all, totally different approach?

the source files are, tagging might not optimal, is. transformation not new subsequently adapted our needs. source code poems in avoided earlier, i'd find solution this.

any help appreciated.

best regards,

christian kirchhoff

this stylesheet:

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform"> <xsl:template match="div[@class='poem']"> <xsl:copy> <xsl:copy-of select="@*"/> <xsl:for-each-group select="*" group-ending-with="br|h4"> <div class="strophe"> <xsl:copy-of select="current-group()/self::p[not(@class)]"/> </div> </xsl:for-each-group> </xsl:copy> </xsl:template> </xsl:stylesheet>

with input:

<div class="poem"> <h4>headline</h4> <p>1st line of 1st verse</p> <p>2nd line of 1st verse</p> <br/> <p>1st line of 2nd verse</p> <p>2nd line of 2nd verse</p> <page n="100"/> <p>3rd line of 2nd verse</p> </div>

output:

<div class="poem"> <div class="strophe"> <p>1st line of 1st verse</p> <p>2nd line of 1st verse</p> </div> <div class="strophe"> <p>1st line of 2nd verse</p> <p>2nd line of 2nd verse</p> <p>3rd line of 2nd verse</p> </div> </div>

with input:

<div class="poem"> <h4>headline</h4> <p class="center">1</p> <p>1st line of 1st verse</p> <p>2nd line of 1st verse</p> <br/> <p class="center">2</p> <p>1st line of 2nd verse</p> <p>2nd line of 2nd verse</p> <page n="100"/> <p>3rd line of 2nd verse</p> </div>

output:

<div class="poem"> <div class="strophe"> <p>1st line of 1st verse</p> <p>2nd line of 1st verse</p> </div> <div class="strophe"> <p>1st line of 2nd verse</p> <p>2nd line of 2nd verse</p> <p>3rd line of 2nd verse</p> </div> </div>

so, stylesheet:

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform"> <xsl:template match="div[@class='poems']"> <xsl:copy> <xsl:copy-of select="@*"/> <xsl:for-each-group select="*[preceding-sibling::h4]" group-starting-with="h4"> <div class="poem"> <xsl:for-each-group select="current-group()" group-ending-with="br"> <div class="strophe"> <xsl:copy-of select="current-group() /self::p[not(@class)]"/> </div> </xsl:for-each-group> </div> </xsl:for-each-group> </xsl:copy> </xsl:template> </xsl:stylesheet>

with input:

<div class="poems"> <h3>poems</h3> <h4>headline</h4> <p>1st line of 1st verse</p> <p>2nd line of 1st verse</p> <br/> <p>1st line of 2nd verse</p> <p>2nd line of 2nd verse</p> <page n="100"/> <p>3rd line of 2nd verse</p> <h4>headline</h4> <p class="center">1</p> <p>1st line of 1st verse</p> <p>2nd line of 1st verse</p> <br/> <p class="center">2</p> <p>1st line of 2nd verse</p> <p>2nd line of 2nd verse</p> <page n="100"/> <p>3rd line of 2nd verse</p> </div>

output:

<div class="poems"> <div class="poem"> <div class="strophe"> <p>1st line of 1st verse</p> <p>2nd line of 1st verse</p> </div> <div class="strophe"> <p>1st line of 2nd verse</p> <p>2nd line of 2nd verse</p> <p>3rd line of 2nd verse</p> </div> </div> <div class="poem"> <div class="strophe"> <p>1st line of 1st verse</p> <p>2nd line of 1st verse</p> </div> <div class="strophe"> <p>1st line of 2nd verse</p> <p>2nd line of 2nd verse</p> <p>3rd line of 2nd verse</p> </div> </div> </div>

xslt-2.0

Comments

Popular posts from this blog

java - How to set log4j.defaultInitOverride property to false in jboss server 6 -

c - GStreamer 1.0 1.4.5 RTSP Example Server sends 503 Service unavailable -

Using ajax with sonata admin list view pagination -