[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Grouping: unordered lists from xml to html

Subject: Re: Grouping: unordered lists from xml to html
From: Michael Ludwig <mlu@xxxxxxxxxxxxx>
Date: Thu, 23 Oct 2008 11:18:35 +0200
Re:  Grouping: unordered lists from xml to html
J. S. Rawat schrieb:
Hi List,
I am doing html to xml conversion and we need grouping in this regard.

Hi Rawat,


looks like this has remained unanswered.

In XSLT 2.0, use xsl:for-each-group with group-adjacent as shown below.
The application of the different types of xsl:for-each-group are very
well explained in Michael Kay's XSLT 2.0 Reference.

Michael Ludwig

XML
<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>

REQUIRED OUTPUT
<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>

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

  <xsl:template match="summary">
    <html>
      <body>
        <xsl:for-each-group select="*" group-adjacent="@bullet">
          <xsl:apply-templates select="."/>
        </xsl:for-each-group>
      </body>
    </html>
  </xsl:template>

  <xsl:template match="para[ @bullet = 0 ]">
    <xsl:for-each select="current-group()">
      <p><xsl:value-of select="."/></p>
    </xsl:for-each>
  </xsl:template>

  <xsl:template match="para[ @bullet = 1 ]">
    <ul>
      <xsl:for-each select="current-group()">
        <li><xsl:value-of select="."/></li>
      </xsl:for-each>
    </ul>
  </xsl:template>

</xsl:stylesheet>

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.