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 May 21st, 2004, 08:29 AM
Authorized User
 
Join Date: Jun 2003
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Default Putting generic content into table rows

Hello there,

I'm transforming some XML using an XSL file,
The XML holds form objects in groups,
The XSL needs to place groups into tables and the form objects into table cells,
However I only want to have 2 table cells to a row.

Here's a sample of my XML...
Code:
<?xml version="1.0"?>
  <document xmlns:xf="http://apache.org/cocoon/jxforms/1.0">
    <xf:form id="generic-refer" action="refer" method="GET">
      <xf:group class="personalDetails">
        <xf:label>Personal Details</xf:label>
    <xf:input ref="/surname">
      <xf:label>Surname</xf:label>
      <xf:violations class="error"/>
    </xf:input>
    <xf:input ref="/firstname">
      <xf:label>Firstname</xf:label>
      <xf:violations class="error"/>
    </xf:input>
        <xf:select1 ref="/gender" appearance="full">
      <xf:label>Gender</xf:label>
      <xf:item>
        <xf:label>Male</xf:label>
        <xf:value>m</xf:value>
      </xf:item>
      <xf:item>
        <xf:label>Female</xf:label>
        <xf:value>f</xf:value>
      </xf:item>
    </xf:select1>
      </group>
    </xf:form>
  </document>
  As you can see there are tags with form element names such as input and select, in the full XML there are submit buttons and so on.

Now my XSL looks like this so far...
Code:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xf="http://apache.org/cocoon/jxforms/1.0">
  <xsl:output method="xml" omit-xml-declaration="no"/>
    <xsl:template match="/">
      <html>
        <head>
      <title>Form Test</title>
    </head>
    <body>
      <table border="1">
        <xsl:apply-templates select="//xf:group[@class='personalDetails']"/> 
          </table>
    </body>
      </html>
    </xsl:template>

    <xsl:template match="xf:group">
      <tr>
    <td colspan="2"><xsl:value-of select="xf:label"/></td>
      </tr>
      <xsl:apply-templates select="*[position() div 2 != round(position() div 2)]"/>
    </xsl:template>

    <xsl:template match="xf:label">
      <xsl:value-of select="xf:label"/>
    </xsl:template>

    <xsl:template match="xf:input">    
      <xsl:param name="pos" select="position()"/>
      <tr>
     <td><xsl:value-of select="xf:label"/>#160;
      <input name="{@ref}" type="text" value="{xf:value/text()}" class="refTbox">
        <xsl:copy-of select="@*[not(name()='ref')]"/>
        <xsl:apply-templates select="xf:hint"/>
      </input>
    </td>
    <td>
      <xsl:apply-templates select="../*[position()=$pos * 2]" mode="Ievens"/>
    </td>
      </tr>
    </xsl:template>

    <xsl:template match="xf:input" mode="Ievens">    
      <xsl:value-of select="@ref"/>
      <input name="{@ref}" type="text" value="{xf:value/text()}" class="refTbox">
        <xsl:copy-of select="@*[not(name()='ref')]"/>
    <xsl:apply-templates select="xf:hint"/>
      </input>    
    </xsl:template>

    <xsl:template match="xf:select1[@appearance='full']">
      <xsl:param name="pos" select="position()"/>
    <tr>
          <td><xsl:value-of select="xf:label"/>#160;
        <xsl:variable name="selected" select="xf:value"/>
        <xsl:variable name="ref" select="@ref"/>
        <xsl:for-each select="xf:item">
          <input name="{$ref}" type="radio" value="{xf:value}">
            <xsl:copy-of select="@*[not(name()='ref')]"/>
        <xsl:if test="xf:value = $selected">
          <xsl:attribute name="checked"/>
        </xsl:if>
          </input>
          <xsl:value-of select="xf:label"/>
          <br/>
        </xsl:for-each>
      </td>
      <td>
        <xsl:apply-templates select="../*[position()=$pos * 2]" mode="s1evens"/>
      </td>
    </tr>
     </xsl:template>

    <xsl:template match="xf:select1[@appearance='full']" mode="s1evens">    
      <xsl:value-of select="xf:label"/>#160;
      <xsl:variable name="selected" select="xf:value"/>
      <xsl:variable name="ref" select="@ref"/>
        <xsl:for-each select="xf:item">
      <input name="{$ref}" type="radio" value="{xf:value}">
        <xsl:copy-of select="@*[not(name()='ref')]"/>
        <xsl:if test="xf:value = $selected">
          <xsl:attribute name="checked"/>
        </xsl:if>
      </input>
      <xsl:value-of select="xf:label"/>
      <br/>
    </xsl:for-each>
     </xsl:template>
  </xsl:stylesheet>
  *phew!!

Ok sorry about the long code post!

But I'm really not sure where to go next, I want basically to pass through a group with any amount of child nodes (form elements) and have them put into rows of two columns each, my code works if i don't include anything but the xf:input nodes, but how do I get it to work universally, can anyone perhaps guide me to a better way of doing this?

TIA,

Blaise.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Similar Page Content - Making "Generic" Pages robzyc ASP.NET 2.0 Basics 6 May 16th, 2008 09:06 AM
Create generic XSL Template to create table Venkatachalapathy XSLT 5 March 11th, 2008 07:49 AM
How to dynamic display the content of the table? myhrvod Pro Java 0 August 3rd, 2006 12:42 AM
Next Record, Putting Data in Table....Please Help! stacy Beginning PHP 2 July 28th, 2005 04:32 PM
putting xml data in a html <table> rev XSLT 4 September 10th, 2003 08:49 AM





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