Fix for non-item content embedded in lists
Posted by mholmes on 24 Aug 2011 in Activity log
I've written an intermediary stylesheet to split out <list>
elements containing <pb>
and <fw>
children into separate lists with the <pb>
s and <fw>
s outside them. This is processed prior to the main transformation, and has solved the problem for lists. I may revisit it for lg/l at some point. For the record, here's the template (the only non-pass-through template in an identity transform):
<!-- Split out interrupted lists into a sequence of lists with the interruptions
between them. -->
<xsl:template match="list[child::fw or child::pb]">
<!-- Stash a reference to the current list so we can easily refer to it in later nested code. -->
<xsl:variable name="thisList" select="."/>
<xsl:for-each-group select="child::item" group-adjacent="count(preceding-sibling::fw) + count(preceding-sibling::pb)">
<list>
<xsl:for-each select="$thisList/@*">
<xsl:copy/>
</xsl:for-each><xsl:text>
</xsl:text>
<xsl:for-each select="current-group()">
<xsl:copy-of select="."/><xsl:text>
</xsl:text>
</xsl:for-each>
</list><xsl:text>
</xsl:text>
<xsl:variable name="lastItem" select="current-group()[position() = last()]"/>
<xsl:for-each select="$lastItem/following-sibling::fw[preceding-sibling::item[1] = $lastItem] | $lastItem/following-sibling::pb[preceding-sibling::item[1] = $lastItem]">
<xsl:copy-of select="."/><xsl:text>
</xsl:text>
</xsl:for-each><xsl:text>
</xsl:text>
</xsl:for-each-group>
</xsl:template>
This entry was posted by Martin and filed under Activity log.