xsl-list
[Top] [All Lists]

[xsl] with-param looping problem...

2006-10-06 14:44:45
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 -------



--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>