0

レポートを作成したいトランザクションのxmlダンプがあります。(簡略化された)xml構造は次のようになります。

Subject
  id
  name
  license
  event id=key
    result
    eventtype
    date
    action
  charge id=key
    result
    code
    date
 ...etc

サブジェクトごとにID、名前、およびライセンスは1つだけです。しかし、多くのイベントが発生する可能性があり、各主題に対して多くの料金が発生する可能性があります。それぞれが異なる結果をもたらします。

レポート出力はテーブルタイプであり、各サブジェクトには名前、ID、ライセンスのヘッダーがあり、ヘッダーの下にデータトランザクションの複数のブロックがリストされています。各データブロックには、トランザクションのタイプに基づいて異なる値と構造があります。

ヘッダーと各データトランザクションタイプで完全に機能しますが、最初のイベントトランザクションと最初の請求トランザクションのみが出力されます。

(簡略化された)xslは次のようになります。

<xsl:for-each select="file/subject">
  <xsl:if test="not (@subject = preceding-sibling::subject[1])">
    <table width="754" border="2" cellpadding="0">
      <tr>
        <td width="172">ctn: <strong><xsl:value-of select="id"/></strong></td>
        <td width="364">defendant: <strong><xsl:value-of select="name"/></strong></td>
        <td width="200">sid: <strong><xsl:value-of select="license"/></strong></td>
        </tr>
    </table>
  </xsl:if>
  <blockquote>
    <xsl:if test="event/eventType != ' '">
      <table width="695" border="1">
        <tr>
          <td>Event<xsl:value-of select="event/result"/></td>
          <td>Eventtype<xsl:value-of select="event/eventtype"/></td>
          <td>Date<xsl:value-of select="event/date"/></td>
        </tr>
      </table>
    </xsl:if>
    <xsl:if test="charge/code != ' '">
      <table width="695" border="1">
        <tr>
          <td>Charge<xsl:value-of select="charge/result"/></td>
          <td>Code<xsl:value-of select="charge/code"/></td>
          <td>Date<xsl:value-of select="charge/date"/></td>
        </tr>
      </table>
    </xsl:if>
  </blockquote>
</xsl:for-each>

子ノードをスキャンするためにfor-eachを追加する必要があると思いますが、ループを追加するとヘッダーが表示されます。

何かご意見は?

(そして、これまで読んでくれてありがとう。:o)

4

1 に答える 1

0

XSLTで可能な場合は、for-eachを避け、代わりにノードを変換テンプレートに適用します。

私はこれを思いついた、それはあなたがこの遊び場セッションで実行することができる-それがあなたが何を求めているのか大まかにわからない。

    <!-- root and static content -->
    <xsl:template match="/">
        <xsl:apply-templates select='root/Subject' />   
    </xsl:template>

    <!-- iteration content: subject -->
    <xsl:template match='Subject'>
        <table>
            <tr>
                <td>ctn: <strong><xsl:value-of select="id"/></strong></td>
                <td>defendant: <strong><xsl:value-of select="name"/></strong></td>
                <td>sid: <strong><xsl:value-of select="license"/></strong></td>
            </tr>
        </table>
        <xsl:apply-templates select='event' />
        <xsl:apply-templates select='charge' />
    </xsl:template>

    <!-- iteration content: event -->
    <xsl:template match='event'>
        <blockquote>
            <table>
                <tr>
                    <td>Event: <xsl:value-of select="result"/></td>
                    <td>Event type: <xsl:value-of select="eventtype"/></td>
                    <td>Date: <xsl:value-of select="date"/></td>
                </tr>
            </table>
        </blockquote>
    </xsl:template>

    <!-- iteration content: charge -->
    <xsl:template match='charge'>
        <blockquote>
            <table>
                <tr>
                    <td>Charge: <xsl:value-of select="result"/></td>
                    <td>Code: <xsl:value-of select="code"/></td>
                    <td>Date: <xsl:value-of select="date"/></td>
                </tr>
            </table>
        </blockquote>
    </xsl:template>
于 2012-06-22T16:20:22.273 に答える