0

シナリオは次のとおりです。図書館には 5 冊の本があります。著者 A は 1 つのタイトルを書き、ライブラリは 30+14=44 回チェックアウトされた 2 つのコピーを所有しています 著者 B は 2 つの本を書き、ライブラリは 18+9=27 でチェックアウトされたタイトル B の 2 つのコピーを所有しています回と 41 回チェックアウトされたタイトル C の 1 つのコピー。

私のXMLは次のようになります。

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="popauthors.xsl"?>
<report>
  <catalog>
    <marc>
      <marcEntry tag="100" label="Personal Author" ind="1 ">Author A</marcEntry>
      <marcEntry tag="245" label="Title" ind="10">Title A</marcEntry>
    </marc>
  <call>
    <item>
      <totalCharges>30</totalCharges>
        <itemID>1234</itemID>
    </item>
    <item>
      <totalCharges>14</totalCharges>
      <itemID>2345</itemID>
    </item>
  </call>
</catalog>
<catalog>
  <marc>
    <marcEntry tag="100" label="Personal Author" ind="1 ">Author B</marcEntry>
    <marcEntry tag="245" label="Title" ind="10">Title B</marcEntry>
  </marc>
  <call>
    <item>
      <totalCharges>18</totalCharges>
      <itemID>3456</itemID>
    </item>
    <item>
      <totalCharges>9</totalCharges>
      <itemID>4567</itemID>
    </item>
  </call>
</catalog>
<catalog>
  <marc>
    <marcEntry tag="100" label="Personal Author" ind="1 ">Author B</marcEntry>
    <marcEntry tag="245" label="Title" ind="10">Title C</marcEntry>
  </marc>
  <call>
    <item>
      <totalCharges>41</totalCharges>
      <itemID>5678</itemID>
    </item>
  </call>
</catalog>
</report>

Muenchian のグループ化を試してみました - 著者 A については正しい数値が得られましたが、著者 B については、最初のタイトルの項目と料金のみがカウントされました。複数のタイトルを持つ著者のすべての料金をカウントするには、何を追加すればよいですか?

<?xml version="1.0"?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>

<xsl:key name="popauthor" match="marc" use="marcEntry[@tag='100']"/>

<xsl:template match="/">
    <popauthors>
        <xsl:for-each select="//marc[generate-id(.)=generate-id(key('popauthor', marcEntry[@tag='100'])[1])]">
            <xsl:sort select="marcEntry"/> 

                <popauthorline>
                    <authorName><xsl:value-of select="marcEntry[@tag='100']"/></authorName>
                    <numberOfTitles><xsl:value-of select="count(key('popauthor', marcEntry[@tag='100']))"/></numberOfTitles>
                    <numberOfItems><xsl:value-of select="count(../call/item/itemID)"/></numberOfItems>
                    <TotalCharges><xsl:value-of select="sum(../call/item/totalCharges)"/></TotalCharges>
                </popauthorline>

        </xsl:for-each>
    </popauthors>
</xsl:template>

</xsl:stylesheet>
4

1 に答える 1