[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

with-param looping problem...

Subject: with-param looping problem...
From: Robert Wilkins <wilkins.robert@xxxxxxxxxxx>
Date: Fri, 6 Oct 2006 17:44:22 -0400
resource uid ms project problem
I'm trying to transform xml derived from an MS Project plan. I'm
trying to create a table where each row identifies the resource
(person) assigned to a particular task, but when I loop through the
source, the resource name appears only once. I'm tapped out and tried
everything I can think of. This is a 1.0 stylesheet and I'm using Saxon 6.5.5


The xml looks like this:


<Project> <Tasks> <Task> <UID>1</UID> <ID>1</ID> <Name>Do something</Name> </Task> <Task> <UID>2</UID> <ID>2</ID> <Name>Do something else</Name> </Task> <Task> <UID>3</UID> <ID>3</ID> <Name>Do everything else</Name> </Task> <Task> <UID>4</UID> <ID>4</ID> <Name>A job</Name> </Task> <Task> <UID>5</UID> <ID>5</ID> <Name>A biggger job</Name> </Task> <Task> <UID>6</UID> <ID>6</ID> <Name>the biggest job</Name> </Task> </Tasks> <Resources> <Resource> <UID>1</UID> <ID>1</ID> <Name>Tom</Name> </Resource> <Resource> <UID>2</UID> <ID>2</ID> <Name>Dick</Name> </Resource> <Resource> <UID>3</UID> <ID>3</ID> <Name>Harry</Name> </Resource> </Resources> <Assignments> <Assignment> <UID>1</UID> <TaskUID>1</TaskUID> <ResourceUID>1</ResourceUID> </Assignment> <Assignment> <UID>2</UID> <TaskUID>2</TaskUID> <ResourceUID>2</ResourceUID> </Assignment> <Assignment> <UID>3</UID> <TaskUID>3</TaskUID> <ResourceUID>3</ResourceUID> </Assignment> <Assignment> <UID>4</UID> <TaskUID>4</TaskUID> <ResourceUID>1</ResourceUID> </Assignment> <Assignment> <UID>5</UID> <TaskUID>5</TaskUID> <ResourceUID>2</ResourceUID> </Assignment> <Assignment> <UID>6</UID> <TaskUID>6</TaskUID> <ResourceUID>3</ResourceUID> </Assignment> </Assignments> </Project>

My stylesheet looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
     <xsl:output method="html"/>
     <xsl:key name="task" match="Task" use="UID"/>
     <xsl:key name="job" match="Assignment" use="TaskUID"/>
     <xsl:key name="worker" match="Resource" use="UID"/>

<xsl:template match="/">

         <html>
             <head></head>
             <body>
                 <xsl:for-each select="//Task">
                     <xsl:for-each select="key('task',UID)">
                         <tr>
                             <td>
                                 <xsl:value-of select="key
('task',UID)/Name"/>
                             </td>
                             <td>
                                 <xsl:value-of select="key
('task',UID)/UID"/>
                             </td>
                             <td>
                                 <xsl:call-template name="get-uid">
                                     <xsl:with-param name="rid"
select="key('task',UID)/ResourceUID"/>
                                 </xsl:call-template>
                            </td>
                         </tr>
                     </xsl:for-each>
                 </xsl:for-each>
             </body>
         </html>
     </xsl:template>

    <xsl:template name="get-uid">
        <xsl:param name="rid"/>
        <xsl:call-template name="get-name">
            <xsl:with-param name="rid"/>
        </xsl:call-template>
     </xsl:template>

     <xsl:template name="get-name">
         <xsl:param name="rid"/>
     <xsl:value-of select="key('worker',UID)/Name"/>
     </xsl:template>
</xsl:stylesheet>


The results look like this:


<html>
    <head>
    </head>
    <body>
       <tr>
          <td>Do something</td>
          <td>1</td>
          <td>Tom</td>
       </tr>
       <tr>
          <td>Do something else</td>
          <td>2</td>
          <td>Dick</td>
       </tr>
       <tr>
          <td>Do everything else</td>
          <td>3</td>
          <td>Harry</td>
       </tr>
       <tr>
          <td>A job</td>
          <td>4</td>
          <td></td>
       </tr>
       <tr>
          <td>A biggger job</td>
          <td>5</td>
          <td></td>
       </tr>
       <tr>
          <td>the biggest job</td>
          <td>6</td>
          <td></td>
       </tr>
    </body>
</html>


I can't figure out why this only retrieves the names the first time around. I sure would appreciate some help. My thanks in advance.

------- bob wilkins -------

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Cast Your Vote

We need your help – Vote for DataDirect XML Products!

  • Best SOA or XML site

Winners and finalists announced at SOA World Conference in November.

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2007 All Rights Reserved.