This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Counting elements in parent node




Hi,

I am trying to count the number of times the <TimeSheet> element appears in the following XML. The code for the variable I have defined is shown after
 that and how
I call it from the xsl:template. I want to count the number of <TimeSheet> elements in the source tree and capture it whenever I call the
<xsl:template match="Employee">
WHat I do get is the total number of unique Employees. That's not what I want.

I do get the unique number of <TimeSheet> from the source tree when I define the variable in the <xsl:template match ="TimeSheet">. I am sure this is
easy for
someone who has done it before. I went through the FAQ but could not find anything similar. Your help is appreciated.


Thanks.

XML file:

<Employees>
    <Employee>
      <EmpName>some name</EmpName>
      <EmpUserId>someid</EmpUserId>
      <TimeSheets>
     <TimeSheet>
                 <BeginWeek>10/01/2000</BeginWeek>
                 <EndWeek>10/07/2000</EndWeek>
                 <WeeklyTotal>40</WeeklyTotal>
               </TimeSheet>
     <TimeSheet>
                 <BeginWeek>10/08/2000</BeginWeek>
            <EndWeek>10/14/2000</EndWeek>
                 <WeeklyTotal>40</WeeklyTotal>
               </TimeSheet>
      </TimeSheets>
  </Employee>
  <Employee>
      <EmpName>employee 2</EmpName>
      <EmpUserId>someid-2</EmpUserId>
      <TimeSheets>
     <TimeSheet>
                 <BeginWeek>10/01/2000</BeginWeek>
                 <EndWeek>10/07/2000</EndWeek>
                 <WeeklyTotal>40</WeeklyTotal>
               </TimeSheet>
     <TimeSheet>
                 <BeginWeek>10/08/2000</BeginWeek>
            <EndWeek>10/14/2000</EndWeek>
                 <WeeklyTotal>40</WeeklyTotal>
               </TimeSheet>
      </TimeSheets>
  </Employee>
</Employees>


XSL file:

...
<xsl:template match="Employee">
<xsl:variable name="weekselected">
       <xsl:number from="child::TimeSheets/TimeSheet" level="any"/>
</xsl:variable>
...(some instructions)
<xsl:value-of select="$weekselected" />
...(some instructions)
<xsl:apply-templates select="TimeSheets/TimeSheet" />
...(some instructions)
</xsl:template>

<xsl:template match="TimeSheet">
<xsl:variable name="weekselected">
  <xsl:number level="any" />
</xsl:variable>

...(some instructiuons)

</xsl:template>



 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]