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 February 20th, 2004, 11:46 AM
Registered User
 
Join Date: Jul 2003
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Creating & comparing node sets

I'm trying to write XSLT code to accomplish the following:
1) I have "items sold" in a sales journal document
2) I have "items in inventory" in an inventory document
3) I need to create a node set containing items that match on item ID so that I can then "sum" on cost in order to get the "cost of items sold"

Can someone share some code to accomplish it ... or suggest a better way?

Thanks - Skip (University of Delaware)




Skip White
Professor of Accounting & MIS
Unviersity of Delaware
 
Old February 20th, 2004, 12:10 PM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Sounds fairly straightforward (famous last words). Could you provide a small sample of each document?

On a separate issue is the "Unviersity of Delaware" in your sig related in anyway to the "University of Delaware"?

Joe (MVP - xml)
 
Old February 20th, 2004, 05:49 PM
Registered User
 
Join Date: Jul 2003
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Joe - Thanks for the reply

My documents look like:
Sales journal:
<entryDetail>
   <account> xxx
   <amount> xxx
   <measurableId>rs200
   </entryDetail>
<entryDetail>
   etc.

Inventory document:
<item>
    <itemId> xxx
    <cost> xxx
    </item>
<item>
    <itemId>rs200
    <cost> 49.50
    </item>

So the node set for cost of goods sold will be a subset of the items in the the inventory doc but will match on itemId with the measurableId's in the sales journal doc.




Quote:
quote:Originally posted by joefawcett
 Sounds fairly straightforward (famous last words). Could you provide a small sample of each document?

On a separate issue is the "Unviersity of Delaware" in your sig related in anyway to the "University of Delaware"?

Joe (MVP - xml)
Skip White
Professor of Accounting &amp; MIS
Unviersity of Delaware
 
Old February 21st, 2004, 05:51 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Still not sure I've understood the entire problem but this might point you in the right direction, assuming your entryDetails are in xml like:
Code:
<entries>
  <entryDetail>
    <account>abc</account>
    <amount>xxx</amount>
    <measurableId>rs100</measurableId>
  </entryDetail>
  <entryDetail>
    <account>abc</account>
    <amount>xxx</amount>
    <measurableId>rs200</measurableId>
  </entryDetail>
  <entryDetail>
    <account>def</account>
    <amount>xxx</amount>
    <measurableId>rs300</measurableId>
  </entryDetail>
  <entryDetail>
    <account>def</account>
    <amount>xxx</amount>
    <measurableId>rs200</measurableId>
  </entryDetail>
  <entryDetail>
    <account>ghi</account>
    <amount>xxx</amount>
    <measurableId>rs100</measurableId>
  </entryDetail>
</entries>
then the following shows how to group on measurableId, search the Web for Muenchian grouping for an explanation of how this works:
Code:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:key name="entries-by-id" match="entryDetail" use="measurableId" />

  <xsl:template match="/">
    <html><head><title>Costs</title></head>
    <body>
      <table width="60%" align="center" border="1">
        <caption>Entries Grouped By Id</caption>
        <tbody>
          <xsl:apply-templates/>
        </tbody>
      </table>
    </body>    
    </html>
  </xsl:template>

  <xsl:template match="entries">
    <xsl:for-each select="entryDetail[count(. | key('entries-by-id', measurableId)[1]) = 1]">
          <xsl:sort select="measurableId" />
          <tr><td><xsl:value-of select="measurableId" /></td><td>#xa0;</td></tr> 
          <xsl:for-each select="key('entries-by-id', measurableId)">
              <xsl:sort select="account" />
              <tr><td>#xa0;</td><td><xsl:value-of select="account" /></td></tr>
          </xsl:for-each>
      </xsl:for-each>  
  </xsl:template>
</xsl:stylesheet>
To match up with the other xml you would need to use the document function to bring the inventory document into play and lookup the cost using the measurableId.
If you need more show your hoped for output and input documents that are valid xml.

--

Joe





Similar Threads
Thread Thread Starter Forum Replies Last Post
Joining two node sets dubloons XSLT 6 August 27th, 2007 04:03 PM
Creating a template to generate a node set Chamkaur XSLT 1 July 27th, 2007 02:51 AM
Good way to select & process only one node traxwx XSLT 2 May 21st, 2007 05:08 PM
get node & childs in a DB Tazu XSLT 2 September 29th, 2005 10:20 AM
Creating & Populating Tables jitu ADO.NET 11 June 3rd, 2004 01:04 PM





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