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 April 1st, 2007, 09:52 PM
Registered User
 
Join Date: Apr 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Display orders for a specific customer - XSLT

Hey guys,

I have a problem with XSLT and hopefully someone here can help.

I have the Northwind database and i need to create a stylesheet that will accept a parameter that is the companyID. the output file will then display a table of all the orders for the selected customer.

Ideally i need to display a list of all the customer ID's in a table, then the user can select one as a hyperlink which will link to an anchor at the bottom of the page with a table displaying a list of all the orders for the selected customer.

If anyone has any idea how to do this i would be extremely greatful. I have worked out how to display the customer ID's in a list but need to know how to link to a table below is with the order details for the selected. Here is my code so far.


<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xhtml="http://www.w3.org/1999/xhtml">
<xsl:output method="xml"/>
<xsl:param name="CustID"/>

<xsl:template match="ROOT">

    <xhtml:html>
        <xhtml:body>
            <xhtml:h1>NORTHWIND DATABASE</xhtml:h1>
            <xhtml:table>
            <xhtml:tr>
            <xhtml:th>Customer ID</xhtml:th>
            <xhtml:th>Company Name</xhtml:th>
            </xhtml:tr>
            <xsl:apply-templates/>
            </xhtml:table>
        </xhtml:body>
    </xhtml:html>
</xsl:template>

<xsl:template match="Customers">
    <xhtml:tr>
    <xhtml:td>
        <xhtml:a href="assign2.xslt?CustID={@CustomerID}">
        <xsl:value-of select="@CustomerID"/>
        </xhtml:a>
    </xhtml:td>
    <xhtml:td>
        <xsl:value-of select="@CompanyName"/>
    </xhtml:td>
    </xhtml:tr>
</xsl:template>

</xsl:stylesheet>


Thanks in advance,
Matt

PS. I am using the xalan XSLT parser.
 
Old April 2nd, 2007, 02:31 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

A parameterised stylesheet is probably an inefficient way of doing things as you will need to return the order information for all customers and then filter for the chosen customer ID. It would normally be better to query for just the relevant customer orders and then transform this into a user friendly page.

I'm not sure it is possible to do it the way you want, by passing the customer ID to the stylesheet in the querystring. Normally you would pass the ID to a server-side page, possibly JSP if you are using Java. You then retrieve the order XML, set the parameter and apply the transform.

For more advice you will have to detail your process more. Where is the processing taking place, server-side, client-side or both? What technologies are you employing?

--

Joe (Microsoft MVP - XML)
 
Old April 2nd, 2007, 04:23 AM
Registered User
 
Join Date: Apr 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for the reply Joe,

I agree this is a bad way of doing things but we have been given a university assignment that states we must do things this way. I have found a way of doing it where i can parse in the customer name or order number as a parameter to see a summary. Now all i need to do is figure out how to use Xpath to total up the orders.

Cheers
Matt

 
Old April 2nd, 2007, 04:40 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

I don't know your source XML document, but I'm a bit surprised you're outputting one table row per "Customers" element, rather than one per "Customer".


You haven't really made it clear whether you want to generate a single HTML page that contains full information for all the customers, or whether you want to go back to the server when the user clicks the link. In the latter case you need to write some server-side code that picks up the query parameter from the URL and feeds this as a parameter into a second stylesheet which generates the detail page for a given customer. The details then depend on whether you are using ASP, PHP, Java servlets, or whatever.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference





Similar Threads
Thread Thread Starter Forum Replies Last Post
EPSON POS - customer display unit nigelstanhope C# 1 January 8th, 2008 06:39 AM
Getting fields, specific order from xml using xslt Jaipal XSLT 4 July 23rd, 2007 11:35 AM
Copy specific data in specific cells of sheet2 yogeshyl Excel VBA 1 May 14th, 2007 07:40 AM
How do after i login it will display specific user PHP FAQs 0 July 20th, 2006 08:06 PM
How to search and display in textbox a specific .. arshad mahmood VB Databases Basics 1 July 11th, 2003 08:07 AM





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