[Home] [By Thread] [By Date] [Recent Entries]
I love to play with Kernow's XSLT Playground feature and your case way well prepared for that. With the help of xsl:for-each-group and regular expressions your case can be solved. I did not try to exclude the possibly last P from the OL and I did not check for the alphabetical order. You would have to specify more clearly what should happen, but look at this: <xsl:template match="root">
<xsl:copy>
<xsl:for-each-group select="*"
group-adjacent="if (self::P and
(self::P[matches(., '^[A-Z][.]')] or
preceding-sibling::P[matches(., '^[A-Z][.]')]))
then 0 else position()">
<xsl:choose>
<xsl:when test="current-grouping-key() = 0">
<OL>
<xsl:for-each-group select="current-group()"
group-starting-with="P[matches(., '^[A-Z][.]')]">
<xsl:choose>
<xsl:when test="./self::P[matches(., '^[A-Z][.]')]">
<LI>
<xsl:apply-templates select="current-group()"
mode="join"/>
</LI>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="current-group()"/>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each-group>
</OL>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="."/>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each-group>
</xsl:copy>
</xsl:template><xsl:template match="node()" mode="join"> <xsl:apply-templates select="@*|node()"/> <xsl:value-of select="' '"/> </xsl:template> <xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>It creates <root>
<H1>Heading</H1>
<P>List Heading</P>
<OL>
<LI>A. One big sentence incorrectly placed in P tags </LI>
<LI>B. Another long sentence spanning P tags. </LI>
<LI>C. This should really be one long list item that spans
randomly. Hopefully I am some unrelated text. </LI>
</OL>
</root>Good luck! - Michael Am 13.01.2009 um 23:45 schrieb Graeme Kidd: Hi everyone, I am using XSLT 2.0 and I have three questions about an ordered list in this format: <root> <H1>Heading</H1> <P>List Heading</P> <P>A. One big</P> <P>sentence incorrectly</P> <P>placed in P tags</P> <P>B. Another long</P> <P>sentence spanning P tags.</P> <P>C. This should really</P> <P>be one</P> <P>long</P> <P>list item</P> <P>that spans randomly.</P> <P>Hopefully I am some unrelated text.</P> </root>
|

Cart



