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 November 25th, 2005, 11:28 AM
Registered User
 
Join Date: Nov 2005
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default generating a table w. xslt, newbie problem

Hi,

I am trying to generate a table in which I want to put data, radio buttons) into different columns. These rows should be put in different columns every seven rows. The error msg i get is this:
The 'xsl:text' start tag on line '687' doesn't match the end tag of 'td' in file...
Which is concerned with this line: </td><td>

Code:
<xsl:template name="radiobuttongroup">

        <xsl:for-each select="radiobuttongroup">    

            <xsl:variable name="parent_id"><xsl:value-of select="@id"/></xsl:variable>

            <xsl:call-template name="label"/>
            <table border="1">    
            <tr>
            <td>                    
                <xsl:for-each select="radio">    
                    <xsl:if test = "index mod 7 = 0 ">
                        </td><td>        
                    </xsl:if>                                                
                    <xsl:call-template name="foo"/>                        
                </xsl:for-each>    
            </td>
            </tr>                                    
            </table>
                <xsl:if test="required"><span class="required_field">*</span></xsl:if>                                                    

        </xsl:for-each>    

    </xsl:template>    



<xsl:template name="foo">
    <xsl:variable name="parent_id"><xsl:value-of select="@id"/></xsl:variable>
    <div style="padding-left:3em;">
    <!--
    <xsl:if test = "index mod 7 = 0 ">
            <xsl:call-template name="radiobuttongroup"/>                    
    </xsl:if>                    -->
        <input value="1" type="radio">                                                                            

        <xsl:attribute name="name">ctrl_<xsl:value-of select="../@id"/></xsl:attribute>
        <xsl:attribute name="id">ctrl_<xsl:value-of select="@id"/></xsl:attribute>            

        <xsl:attribute name="value"><xsl:value-of select="hidden-text"/></xsl:attribute>                        

        <xsl:if test = "//values/value[@ctrlid = $parent_id] = label/text">
            <xsl:attribute name="checked">checked</xsl:attribute>                                                            
        </xsl:if>                            
        <xsl:if test="$disable_input">
            <xsl:attribute name="disabled">disabled</xsl:attribute>
        </xsl:if>                                                                                                
        <xsl:call-template name="label"/>                    
        </input>                                                                                                                                                            
        </div>                        
    </xsl:template>
Can I achieve the same thing using a different technique?? Any ideas?
Thanx in advance!

 
Old November 25th, 2005, 11:36 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
Default

the general method for grouping problems based on position is here:
http://sources.redhat.com/ml/xsl-lis.../msg00058.html
 
Old November 25th, 2005, 12:25 PM
Registered User
 
Join Date: Nov 2005
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi, thanks.

I found the example quite complex... is there a nwebie version somewhere? ;)

 
Old November 25th, 2005, 01:26 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
Default

The salient bits are:-
1. find the first one in each group using this syntax <xsl:apply-templates select="radio[(position() mod $group-size) = 1]" />
2. find all others in the group like this <xsl:for-each select=". | following-sibling::title[position() &lt; $group-size]">

note that 1. calls a template, then in the called template you embed the grouped items (in your case radio buttons) in the <td></td> pair

<xsl:template match="radio">
<td>
<xsl:for-each select=". | following-sibling::title[position() &lt; $group-size]">
</td>
</xsl:template>
 
Old November 25th, 2005, 07:28 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Your error is a very fundamental one: you are thinking of XSLT as a language that outputs begin and end tags, not a language that writes nodes to a result tree. If you think about the result tree, it should be very obvious that you can't say "if condition then write half of one node and half of another". What does half a node look like?

See http://www.dpawson.co.uk/xsl/sect2/N7450.html#d9550e13

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old November 26th, 2005, 01:05 PM
Registered User
 
Join Date: Nov 2005
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks!! :D both of u!








Similar Threads
Thread Thread Starter Forum Replies Last Post
Generating a comma-delimited data in XSLT dude153 XSLT 2 November 30th, 2007 12:12 PM
Dynamically generating Javascript (XSLT in IE6) einszwei XSLT 1 June 28th, 2007 01:07 PM
XSLT table problem tulip2006 XSLT 0 December 28th, 2006 05:27 PM
xslt problem: values not displayed in table natjimy XSLT 2 December 1st, 2004 05:05 AM
Generating aspx pages with xml and xslt glaseur XSLT 4 December 3rd, 2003 05:27 AM





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