0

空白時間から次の空白時間までの時間の合計を計算し、それらを出力に表示する必要があるプロジェクトで作業しています。

入力は次のとおりです。

   <Nodes>
       <Node>
         <EmpId>1<EmpId>      
         <InTime></InTime>
         <Hours></Hours>
        </Node>
      <Node>
        <EmpId>1<EmpId>          
        <InTime>10/12/2010</InTime>
         <Hours>5</Hours>
      </Node>
      <Node>
        <EmpId>1<EmpId>
         <InTime>10/13/2010</InTime>
         <Hours>5</Hours>
      </Node>
      <Node>
        <EmpId>1<EmpId>
        <InTime></InTime>
         <Hours></Hours>
      </Node>
      <Node>
        <EmpId>1</EmpId>
        <InTime></InTime>
        <Hours></Hours>
      </Node>
      <Node>
         <EmpId>1</EmpId>
         <InTime>10/14/2010</InTime>
          <Hours>2</Hours>
      </Node>
      <Node>
        <EmpId>1</EmpId>
        <InTime>10/14/2010</InTime>
        <Hours>3</Hours>
      </Node>
   </Nodes>

出力は次のようになります。

<Nodes>
      <Detail>
         <EmpId>1</EmpId>
          <InTime>10/12/2010</InTime>
           <Hours>10</Hours>
      </Detail>
      <Detail>
        <EmpId>1</EmpId>
        <InTime>10/14/2010</InTime>
         <Hours>5</Hours>
      </Detail>
   </Nodes>

誰かがこれについて私を助けることができれば感謝します.

4

1 に答える 1

0

入力XMLの形式が正しくありません(必要な場所にいくつかの<EmpId>タグがあります</EmpId>)が、それが修正されると、これはあなたが説明したとおりになると思います:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="xml" indent="yes"/>

  <xsl:template match="/Nodes">
    <Nodes>
       <xsl:apply-templates select="Node[Hours != '' and not(normalize-space(preceding-sibling::Node[1]/Hours))]" />
    </Nodes>
  </xsl:template>

  <xsl:template match="Node">
    <Detail>
      <xsl:copy-of select="EmpId | InTime"/>
      <Hours>
        <xsl:apply-templates select="." mode="SumHours" />
      </Hours>
    </Detail>
  </xsl:template>

  <xsl:template match="Node[normalize-space(following-sibling::Node[1]/Hours)]" mode="SumHours">
    <xsl:param name="total" select="0" />
    <xsl:apply-templates select="following-sibling::Node[1]" mode="SumHours">
      <xsl:with-param name="total" select="$total + Hours" />
    </xsl:apply-templates>
  </xsl:template>

  <xsl:template match="Node" mode="SumHours">
    <xsl:param name="total" select="0" />
    <xsl:value-of select="$total + Hours"/>
  </xsl:template>

</xsl:stylesheet>
于 2013-01-21T19:25:29.213 に答える