- Match w:p elements with w:pPr/w:style/@w:val = 'code';
- Check if the previous w:p element also has code style, if not, emit the PRE element and handle the whole group of code paragraphs.
The initial code worked ...
<xsl:template match="w:p[w:pPr/w:pStyle/@w:val = 'code']">
<xsl:if test="preceding-sibling::w:p[1]/w:pPr/w:pStyle/@w:val != 'code'">
<pre class='{w:pPr/w:pStyle/@w:val}'>
<xsl:apply-templates select='.' mode="pre" />
</pre>
</xsl:if>
</xsl:template>
... but only until I've decided to add a border around the code style in Word. The border creates a wx:pBdrGroup in WordProcessingML ...
... and the xsl:if test fails if there is no preceding w:p element. To make the code work, I had to reverse the test condition and add a not at the beginning:
<xsl:template match="w:p[w:pPr/w:pStyle/@w:val = 'code']">
<xsl:if test="not(preceding-sibling::w:p[1]/w:pPr/w:pStyle/@w:val = 'code')">
... rest of code ...
</xsl:if>
</xsl:template>
No comments:
Post a Comment