Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XSLT
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old November 25th, 2005, 11:28 AM
Registered User
 
Join Date: Nov 2005
Location: stockholm, , Sweden.
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!

Reply With Quote
  #2 (permalink)  
Old November 25th, 2005, 11:36 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , United Kingdom.
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
Reply With Quote
  #3 (permalink)  
Old November 25th, 2005, 12:25 PM
Registered User
 
Join Date: Nov 2005
Location: stockholm, , Sweden.
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? ;)

Reply With Quote
  #4 (permalink)  
Old November 25th, 2005, 01:26 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , United Kingdom.
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>
Reply With Quote
  #5 (permalink)  
Old November 25th, 2005, 07:28 PM
mhkay's Avatar
Wrox Author
Points: 18,277, Level: 58
Points: 18,277, Level: 58 Points: 18,277, Level: 58 Points: 18,277, Level: 58
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,933
Thanks: 0
Thanked 282 Times in 277 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
Reply With Quote
  #6 (permalink)  
Old November 26th, 2005, 01:05 PM
Registered User
 
Join Date: Nov 2005
Location: stockholm, , Sweden.
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks!! :D both of u!



Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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 02: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



All times are GMT -4. The time now is 05:28 PM.


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.