p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


Go Back   p2p.wrox.com Forums > XML > XSLT
I forgot my password Register Now
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 p2p Programmer to Programmer discussion community. This is a community of more than 40,000 computer programmers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining our free Wrox p2p community you can post your own programming questions and respond to other programmers’ questions. Registered users also don't have to see the ads that are displayed to guests. Registration is fast, simple and absolutely free so please, join today!
Join today and post to win prizes! Post more to increase your chances of being Wrox’s top poster of the month.

Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old April 21st, 2004, 10:25 PM
Registered User
Points: 15, Level: 1
Points: 15, Level: 1 Points: 15, Level: 1 Points: 15, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: , , .
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default XML to HTML Table with Sorting and Distinct

I am have XML document where I need to first select some of the nodes via some sort of distinct function and then for each type select sorted list of other nodes. Can someone send some examples of doing this?
Sincerely, Victor.


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #2 (permalink)  
Old April 22nd, 2004, 03:50 AM
Friend of Wrox
Points: 2,450, Level: 20
Points: 2,450, Level: 20 Points: 2,450, Level: 20 Points: 2,450, Level: 20
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: , , United Kingdom.
Posts: 1,212
Thanks: 0
Thanked 0 Times in 0 Posts
Default

why don't you show us what your xml looks like (or maybe just the relevant bit if its large), and also what you want the output to look like, and we'll see what we can do.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #3 (permalink)  
Old April 22nd, 2004, 01:22 PM
Registered User
Points: 15, Level: 1
Points: 15, Level: 1 Points: 15, Level: 1 Points: 15, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: , , .
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for the reply.
Here’s what I need. I have a complex xml structure that has several request codes, and a xmlCategoryNodes with attributes: Code and Type.
I need to reformat this into the HTML where for each xmlCategoryTypes (across all Request Codes) I get the lowest of Codes (sort order does not matter at this point). Once I understand how the process works I hope then I can reformat into a specific HTML table structure.

Here is what the resulting format should look like:

xmlCategoryNode Type - SU
-- xmlCategoryNode Code 11

xmlCategoryNode Type - OB
 -- xmlCategoryNode Code 8I

xmlCategoryNode Type - OS
 -- xmlCategoryNode Code 6A

Here’s the source XML:

<xmlResponse>
    <MessageHeader SegId="MSGHDR">
        <MessageId>CCC</MessageId>
        <SessionId>1234</SessionId>
    </MessageHeader>
    <xmlCodeResponse SegId="CAT2">
        <Request Code="111"/>
        <xmlCategoryNode Code="11">
            <CatType>SU</CatType>
        </xmlCategoryNode>
        <xmlCategoryNode Code="ST">
            <CatType>SU</CatType>
        </xmlCategoryNode>
        <xmlCategoryNode Code="9A">
            <CatType>OB</CatType>
        </xmlCategoryNode>
        <xmlCategoryNode Code="8I">
            <CatType>OB</CatType>
        </xmlCategoryNode>
        <xmlCategoryNode Code="7A">
            <CatType>OS</CatType>
        </xmlCategoryNode>
        <xmlCategoryNode Code="6A">
            <CatType>OS</CatType>
        </xmlCategoryNode>
        <xmlCategoryNode Code="OV">
            <CatType>OS</CatType>
        </xmlCategoryNode>
    </xmlCodeResponse>
    <xmlCodeResponse SegId="CAT2">
        <Request Code="222"/>
        <xmlCategoryNode Code="11">
            <CatType>SU</CatType>
        </xmlCategoryNode>
        <xmlCategoryNode Code="7A">
            <CatType>OS</CatType>
        </xmlCategoryNode>
        <xmlCategoryNode Code="6A">
            <CatType>OS</CatType>
        </xmlCategoryNode>
    </xmlCodeResponse>
    <xmlCodeResponse SegId="CAT2">
        <Request Code="333"/>
        <xmlCategoryNode Code="11">
            <CatType>SU</CatType>
        </xmlCategoryNode>
        <xmlCategoryNode Code="7A">
            <CatType>OS</CatType>
        </xmlCategoryNode>
        <xmlCategoryNode Code="6A">
            <CatType>OS</CatType>
        </xmlCategoryNode>
    </xmlCodeResponse>
</xmlResponse>

Sorry for the long xml source, but I think that’s the only way to relay the requirements.
Thanks, V.



Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #4 (permalink)  
Old April 23rd, 2004, 05:04 AM
Friend of Wrox
Points: 2,450, Level: 20
Points: 2,450, Level: 20 Points: 2,450, Level: 20 Points: 2,450, Level: 20
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: , , United Kingdom.
Posts: 1,212
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Here you go Victor. Its a standard method known as Meunchian Grouping which uses keys to group the source XML by CatType. If you're not familiar with this method there's a v good explanation here http://www.jenitennison.com/xslt/gro...muenchian.html
Code:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:key name="ResponseByCat" match="xmlCodeResponse/xmlCategoryNode" use="CatType"/>
    <xsl:template match="/">
        <html>
            <head>
                <title>Muenchian Grouping Example</title>
            </head>
            <body>
                <h3>Muenchian Grouping Example</h3>

                <xsl:apply-templates select="xmlResponse/xmlCodeResponse/xmlCategoryNode[generate-id()=generate-id(key('ResponseByCat', CatType)[1])]">
                    <xsl:sort select="CatType" order="ascending"/>
                </xsl:apply-templates>
            </body>
        </html>
    </xsl:template>
    <xsl:template match="xmlCategoryNode">
        <xsl:value-of select="CatType"/> | 

        <xsl:for-each select="key('ResponseByCat', CatType)">
            <xsl:sort select="@Code" order="ascending"/>

            <xsl:if test="position()=1">
                <xsl:value-of select="@Code"/><br/>
            </xsl:if>
        </xsl:for-each>
    </xsl:template>
</xsl:stylesheet>
This produces the following output:
OB | 8I
OS | 6A
SU | 11

If you have any problems converting the output to the format you want, or indeed if you have any other questions about the stylesheet, just ask.

rgds
Phil
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #5 (permalink)  
Old April 23rd, 2004, 07:29 PM
Registered User
Points: 15, Level: 1
Points: 15, Level: 1 Points: 15, Level: 1 Points: 15, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: , , .
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Phil,
Thanks a million for your help. This sheds light on the XSL sorting for me.
However, here’s my dilemma, ultimately I need to display the data on an ASP.NET web page. I am using an XML API, where I issue a request and get 2 XML responses. Then I have to combine the data from both responses sort them use the lowest price for both each type of product, as well as each product and then present it users.
The code sample you helped me with allows me to group by category type, but I was having trouble getting unique products per category type.
And in the end I am wondering is it best to do with XSL style sheets or do it in some form with .NET XPath objects.
Any advice would be greatly appreciated.
Thanks, V.


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Using PHP to create HTML table from external XML rydog65 Moderated Pro PHP 0 March 26th, 2008 06:18 PM
transform a xml to a html table robert_trudel_fr XSLT 3 December 3rd, 2006 02:16 PM
constructing a HTML table from xml data using xslt rameshnarayan XSLT 0 September 19th, 2005 07:53 AM
XML List -> HTML table JPMRaptor XSLT 1 November 14th, 2003 10:19 PM
putting xml data in a html <table> rev XSLT 4 September 10th, 2003 09:49 AM



All times are GMT -4. The time now is 12:22 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
© 2008 Wiley Publishing, Inc