|
Subject:
|
XSLT 1.0 Grouping
|
|
Posted By:
|
kwilliams
|
Post Date:
|
1/11/2006 5:30:36 PM
|
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'" /><!-- Passed parameter from ASP.NET script--> <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
|
|