Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 1st, 2011, 07:59 PM
Registered User
 
Join Date: Apr 2008
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default how to obtain this output using XSLT

I currently have a fieldgroup with several field tag listed below.

<fieldgroup cols="3">
<field>
<field>
<field>
<field>
<field>
</fieldgroup>

How can I create a html table so that it will create a new table row for every 3 field tag

<table>
<tr>
<td/>
<td/>
<td/>
</tr>
<tr>
<td/>
<td/>
</tr>
</table>

Thanks.
 
Old September 5th, 2011, 05:26 AM
Authorized User
 
Join Date: Sep 2011
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I think this will give you desired output:

Code:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="xml" indent="yes"/>

    <xsl:template match="@* | node()">
        <xsl:copy>
            <xsl:apply-templates select="@* | node()"/>
        </xsl:copy>
    </xsl:template>
  <xsl:template match="fieldgroup">
    <table>
      <xsl:for-each-group select="*"
                 group-ending-with="*[position() mod 3 = 0]">
        <tr>
          <xsl:for-each select="current-group()">
            <td>
              <xsl:apply-templates  select="field"/>
            </td>
          </xsl:for-each>
        </tr>
      </xsl:for-each-group>
    </table>
  </xsl:template>
</xsl:stylesheet>
Mohan





Similar Threads
Thread Thread Starter Forum Replies Last Post
how to get the output in xslt in following case? gandhit XSLT 0 July 6th, 2011 05:44 AM
How to produce this output in XSLT 1.0 UndeadHalfOrc XSLT 1 December 9th, 2010 04:34 AM
XSLT Variable output mrame XSLT 2 March 26th, 2009 06:51 AM
XSLT to get hyperlinks in output ashv XSLT 2 December 7th, 2008 06:14 AM
XSLT Looks right, but no output Alderian72 XSLT 1 June 9th, 2005 08:47 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.