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 January 11th, 2006, 06:30 PM
Banned
 
Join Date: Jul 2005
Posts: 317
Thanks: 0
Thanked 0 Times in 0 Posts
Default XSLT 1.0 Grouping

I'm almost done developing a site that uses XSLT 1.0. I've downloaded the Saxon 2.0 Processor, but I'm going to have to redevelop some pages for it to work in that. So in the meantime, I have this problem:

XML FILE:
<faqs>
    <faq id="1">
        <category>First Category</category>
        <sub_category>Group A</sub_category>
        <question>Question 1</question>
        <answer>Answer 1</answer>
    </faq>
    <faq id="2">
        <category>First Category</category>
        <sub_category>Group A</sub_category>
        <question>Question 2</question>
        <answer>Answer 2</answer>
    </faq>
    <faq id="3">
        <category>First Category</category>
        <sub_category>Group A</sub_category>
        <question>Question 3</question>
        <answer>Answer 3</answer>
    </faq>
    <faq id="4">
        <category>First Category</category>
        <sub_category>Group B</sub_category>
        <question>Question 4</question>
        <answer>Answer 4</answer>
    </faq>
    <faq id="5">
        <category>First Category</category>
        <sub_category>Group B</sub_category>
        <question>Question 5</question>
        <answer>Answer 5</answer>
    </faq>
</faqs>

XSLT FILE:
...
<xsl:param name="record_id" select="'First Category'" />
<xsl:for-each select="faqs/faq[category = $record_id]">
    <xsl:sort select="sub_category" data-type="text" order="ascending" />
    <xsl:sort select="question" data-type="text" order="ascending" />
    <xsl:if test="sub_category != '' and position() = 1">
        <tr>
            <td colspan="2">
                <strong><xsl:value-of select="sub_category" /></strong>
            </td>
        </tr>
    </xsl:if>
    <tr>
        <td>
            <xsl:value-of select="question" />
        </td>
    </tr>
</xsl:for-each>
...

ACTUAL HTML OUTPUT:
<table>
    <tr>
        <td>Group A</td>
    </tr>
    <tr>
        <td>Question 1</td>
    </tr>
    <tr>
        <td>Question 2</td>
    </tr>
    <tr>
        <td>Question 3</td>
    </tr>
    <tr>
        <td>Question 4</td>
    </tr>
    <tr>
        <td>Question 5</td>
    </tr>
</table>

WANTED HTML OUTPUT:
<table>
    <tr>
        <td>Group A</td>
    </tr>
    <tr>
        <td>Question 1</td>
    </tr>
    <tr>
        <td>Question 2</td>
    </tr>
    <tr>
        <td>Question 3</td>
    </tr>
    <tr>
        <td>Group B</td>
    </tr>
    <tr>
        <td>Question 4</td>
    </tr>
    <tr>
        <td>Question 5</td>
    </tr>
</table>

This setup does display the "sub_category" at the beginning of the entire list, but how can I get the out to be displayed how I'd like it to be, as I've noted above under "WANTED HTML OUTPUT"? Thanks for any help.

KWilliams





Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem of grouping in XSLT LeoMathew XSLT 2 September 11th, 2008 09:38 AM
Grouping with XSLT 1.0 rodmcleay XSLT 1 January 14th, 2008 11:42 PM
XSLT Grouping vernc XSLT 2 October 2nd, 2007 03:59 AM
XSLT Grouping Help Missy XSLT 0 December 14th, 2005 10:28 PM
Grouping Elements using XSLT mathuranuj XSLT 2 June 21st, 2005 02:56 AM





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