This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
RE: unordered lists from xml to html
- From: "Michael Kay" <michael dot h dot kay at ntlworld dot com>
- To: <xsl-list at lists dot mulberrytech dot com>
- Date: Sun, 28 Apr 2002 16:10:59 +0100
- Subject: RE: [xsl] unordered lists from xml to html
- Reply-to: xsl-list at lists dot mulberrytech dot com
You'll find that this is a specific example showing how to use the new
grouping facilities in http://www.w3.org/TR/xslt20 - we included it in our
list of cases studies specifically because it's hard to to in XSLT 1.0.
Using Saxon 7.0, you can do
<xsl:for-each-group group-adjacent="@bullet">
<xsl:choose>
<xsl:when test="@bullet=0">
<xsl:apply-templates select="current-group()" mode="p"/>
</xsl:when>
<xsl:when test="@bullet=1">
<ul>
<xsl:apply-templates select="current-group()" mode="li"/>
</ul>
</xsl:choose>
</xsl:for-each-group>
With XSLT 1.0, your best bet is a recursive template such as:
<xsl:template match="para[@bullet=0]">
<p><xsl:apply-templates/></p>
<xsl:apply-templates select="following-sibling::para[1]"/>
</xsl:template>
<xsl:template
match="para[@bullet=1][preceding-sibling::para[1][@bullet=1]]">
<li><xsl:apply-templates/></li>
<xsl:apply-templates select="following-sibling::para[1]"/>
</xsl:template>
<xsl:template
match="para[@bullet=1][not(preceding-sibling::para[1][@bullet=1]])">
<ul>
<li><xsl:apply-templates/></li>
<xsl:apply-templates select="following-sibling::para[1]"/>
</ul>
</xsl:template>
<xsl:template match="summary">
<xsl:apply-templates select="para[1]"/>
</xsl:template>
Michael Kay
Software AG
home: Michael.H.Kay@ntlworld.com
work: Michael.Kay@softwareag.com
> -----Original Message-----
> From: owner-xsl-list@lists.mulberrytech.com
> [mailto:owner-xsl-list@lists.mulberrytech.com]On Behalf Of Ian Hord
> Sent: 28 April 2002 03:32
> To: xsl-list@lists.mulberrytech.com
> Subject: [xsl] unordered lists from xml to html
>
>
> Hi,
>
> I am new to xsl and struggling with converting some xml to
> html. For example
> I have the following
>
> <summary>
> <para bullet=1>This is paragraph 1
> /para>
> <para bullet=0>This is paragraph 2
> /para>
> <para bullet=1>This is paragraph 3
> /para>
> <para bullet=1>This is paragraph 4
> /para>
> </summary>
>
> I want to convert it to the following html using xsl
>
> <ul>
> <li>This is paragraph 1</li>
> </ul>
> <p>This is paragraph 2</p>
> <ul>
> <li>This is paragraph 3</li>
> <li>This is paragraph 4</li>
> </ul>
>
> You will see that the attributes in the para element
> determine whether the
> paragraph should be in a bullet or not.
>
> If anyone can suggest a solution I will be most grateful.
> Thanks in advance,
>
> Ian Hord
>
>
> XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
>
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list