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 12th, 2007, 12:37 PM
Registered User
 
Join Date: Apr 2006
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default Grouping in xsl

Hi,

I have following xml file.

Now 1st <inner name="name1"> of 1st <outer> contains 3 <a> tags. But 1st <inner name="name1"> of 2nd <outer> contains 4 <a> tags. The 4th <a> have two children <name>test4</name> and <value>444</value>.

At the time of display 'test4' should come after 'test111' and since 1st <inner> does not have 4th <a> tag so the
output should be test4 : blank-space | 444

But now test4 comes at the last....

Thnx in advance,
Saurabh

-------------
doc.xml
----------------

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="test.xsl"?>
<doc>
    <outer>
        <inner name="name1">
            <a>
                <name>test1</name>
                <value>1</value>
            </a>
            <a>
                <name>test11</name>
                <value>11</value>
            </a>
            <a>
                <name>test111</name>
                <value>111</value>
            </a>
        </inner>
        <inner name="name2">
            <a>
                <name>test2</name>
                <value>2</value>
            </a>
            <a>
                <name>test22</name>
                <value>22</value>
            </a>
            <a>
                <name>test222</name>
                <value>222</value>
            </a>
        </inner>
    </outer>
    <outer>
        <inner name="name1">
            <a>
                <name>test1</name>
                <value>11</value>
            </a>
            <a>
                <name>test11</name>
                <value>222</value>
            </a>
            <a>
                <name>test111</name>
                <value>333</value>
            </a>
            <a>
                <name>test4</name>
                <value>444</value>
            </a>
        </inner>
        <inner name="name2">
            <a>
                <name>test2</name>
                <value>99</value>
            </a>
            <a>
                <name>test22</name>
                <value>999</value>
            </a>
            <a>
                <name>test222</name>
                <value>4545</value>
            </a>
        </inner>
    </outer>
</doc>

-----------------------------------
test.xsl
-----------------------------------

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="html"/>
    <xsl:key name="AttrName1" match="a" use="name"/>
    <xsl:template match="/doc">
        <html>
            <body>
                <xsl:apply-templates select="outer/inner"/>
            </body>
        </html>
    </xsl:template>
    <xsl:template match="inner">
        <xsl:for-each select="a[generate-id() = generate-id(key('AttrName1', name)[1])]">
            <xsl:value-of select="name"/>
            <xsl:text> : </xsl:text>
            <xsl:for-each select="key('AttrName1', name)">
                <xsl:value-of select="value"/>
                <xsl:text> | </xsl:text>
            </xsl:for-each>
            <br/>
            <xsl:text>##############</xsl:text>
            <br/>
        </xsl:for-each>
    </xsl:template>
</xsl:stylesheet>



----------------------
Current output
----------------------

test1 : 1 | 11 |
##############
test11 : 11 | 222 |
##############
test111 : 111 | 333 |
##############
test2 : 2 | 99 |
##############
test22 : 22 | 999 |
##############
test222 : 222 | 4545 |
##############
test4 : 444 |
##############






----------------
Expected Output
-----------------

test1 : 1 | 11 |
##############
test11 : 11 | 222 |
##############
test111 : 111 | 333 |
##############
test4 : blank-space | 444 |
##############
test2 : 2 | 99 |
##############
test22 : 22 | 999 |
##############
test222 : 222 | 4545 |
##############








Similar Threads
Thread Thread Starter Forum Replies Last Post
Protect cells and allow grouping/un-grouping sfreuden Excel VBA 4 December 14th, 2006 08:01 AM
xsl grouping aiyer0912 XSLT 9 November 7th, 2006 12:13 PM
Section Grouping (XSL Newbie!) vjlomas XSLT 1 February 4th, 2005 04:00 AM
XSL Grouping and Filtering xrow XSLT 1 October 13th, 2004 11:12 AM
XSL Transform with xsl string NOT xsl file skin XSLT 0 June 16th, 2003 07:30 AM





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