<xsl:for-each select="//text:h | //text:p">
xsl:choose
<xsl:when test="@text:style-name='h2'">
<xsl:if test="preceding-sibling::node()[2]/@text:style-name != 'h1'">
<h1>
<xsl:value-of select="preceding-sibling::text:p[@text:style-name = 'h1']"/>
</h1>
...