|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: grouping list items by attribute
Please try this stylesheet
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml" indent="yes" />
<xsl:template match="/tx.list">
<ol>
<xsl:for-each select="tx.li">
<xsl:choose>
<xsl:when test="@level = '0'">
<li><xsl:value-of select="tx.p" /></li>
</xsl:when>
<xsl:otherwise>
<xsl:if test="(position() = 1) or
preceding-sibling::tx.li[1]/@level = '0'">
<ul>
<li><xsl:value-of select="tx.p" /></li>
<xsl:call-template name="printli">
<xsl:with-param name="list"
select="following-sibling::tx.li" />
</xsl:call-template>
</ul>
</xsl:if>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</ol>
</xsl:template>
<xsl:template name="printli">
<xsl:param name="list" />
<xsl:if test="$list/@level = '1'">
<li><xsl:value-of select="tx.p" /></li>
<xsl:call-template name="printli">
<xsl:with-param name="list" select="$list[position() > 1]" />
</xsl:call-template>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
Regards,
Mukul
On 10/4/05, Lynn Alford <lynn.alford@xxxxxxxxxx> wrote:
> Given this as the input
>
> <tx.list style="ID1c6">
> <tx.li level="0" number="1. ">
> <tx.p style="ID1a2">List1</tx.p>
> </tx.li>
> <tx.li level="0" number="2. ">
> <tx.p style="ID1a2">List2</tx.p>
> </tx.li>
> <tx.li level="1" number="o?= ">
> <tx.p style="ID1a2">Sublist 1</tx.p>
> </tx.li>
> <tx.li level="1" number="o?= ">
> <tx.p style="ID1a2">Sublist 2</tx.p>
> </tx.li>
> <tx.li level="1" number="o?= ">
> <tx.p style="ID1a2">Sublist 3</tx.p>
> </tx.li>
> <tx.li level="0" number="3. ">
> <tx.p style="ID1a2">List3</tx.p>
> </tx.li>
> </tx.list>
>
> The preferred outcome would be
>
> <ol>
> <li>List1</li>
> <li>List2</li>
> <ul>
> <li>Sublist 1</li>
> <li>Sublist 2</li>
> <li>Sublist 3</li>
> </ul>
> <li>List3</li>
> </ol>
>
> My basic problem is I can't quite figure out how you can use an increase in
> level to trigger the start of a new list. Especially when the lists may be
> nested much deeper and any level may be either ordered or unordered
> lists. Siblings at the same level I can do easily enough.
>
> Lynn
>
> Lynn Alford Tel (07) 47 81 6256
> ITR Email: imla@xxxxxxxxxx
> JCU QLD 4811 Australia ICQ: 64096907
> MSN: nicarra60@xxxxxxxxxxx Y!: nicarra60
>
> 'I think an "uncatched exception" deserves three bug reports: one for the
> exception, one for not catching it, and one for abuse of the English
> language.' Michael Kay
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








