0

大学の授業に関する情報を含む XML があります。クラスは、タイトル、コース番号、総単位数で表示されます。

私の XSLT は、データを研究分野ごとにグループ化し、コース番号別にクラスを一覧表示し、コースの説明と合計クレジット数を提供します。すべて正常に動作していますが、クレジット時間の最終的な表示を微調整したいと思います。

各クラスには、最低でも 1 ~ 4 クレジットがあります。一部のクラスには最大クレジット数があります。

<CRSMINCRED1>私の XSLT は、最小クレジットと最大クレジット (<CRSMAXCRED1>存在する場合) の両方をプルします。

次に、XSLT は最終的な表示を作成して、次のいずれかのように表示します。

クラス データ機能のみ<CRSMINCRED1>の場合、表示は次のようになります。「1 単位時間」「2 単位時間」「3 単位時間」「4 単位時間」

クラス データに両方の特徴が <CRSMINCRED1>あり<CRSMAXCRED1>、表示が次のようになっている場合: 「1 ~ 4 単位時間」。

最初の項目以外はすべて問題ありません。コースに最小クレジットが「1」しかなく、最大クレジットがない場合、表示を次のようにしたいと思います。

「1クレジットアワー」

「変数」ステートメントと「if」ステートメントを作成しようとしましたが、成功しませんでした。

サンプル XML を次に示します。

<?xml version="1.0" encoding="UTF-8"?>
<CrystalReport>
<Details Level="1">
<Section SectionNumber="0">
<CRSTITLE1>Clinical Applications of CT I</CRSTITLE1>
<DEPTSDESC1>Diagnostic Medical Imaging</DEPTSDESC1>
<CRSNO1>2511</CRSNO1>
<CRSMINCRED1>3</CRSMINCRED1>
<CRSMAXCRED1/>
</Section>
</Details>
<Details Level="1">
<Section SectionNumber="0">
<CRSTITLE1>Clinical Applications of CT II</CRSTITLE1>
<CRSDEPTS1>DMI</CRSDEPTS1>
<DEPTSDESC1>Diagnostic Medical Imaging 2</DEPTSDESC1>
<CRSNO1>2512</CRSNO1>
<CRSMINCRED1>1</CRSMINCRED1>
<CRSMAXCRED1>4</CRSMAXCRED1>
</Section>
</Details>
<Details Level="1">
<Section SectionNumber="0">
<CRSTITLE1>Clinical Applications of CT III</CRSTITLE1>
<CRSDEPTS1>DMI</CRSDEPTS1>
<DEPTSDESC1>Diagnostic Medical Imaging 3</DEPTSDESC1>
<CRSNO1>2513</CRSNO1>
<CRSMINCRED1>1</CRSMINCRED1>
<CRSMAXCRED1/>
</Section>
</Details>
</CrystalReport>

これは、私が作業しようとしている XSLT の一部です。

<xsl:template match="CrystalReport">
...
 <xsl:apply-templates select="Section/CRSMINCRED1|Section/CRSMAXCRED1"/>

</xsl:template>

<xsl:template match="Section/CRSMINCRED1">
<xsl:if test=". = 1">
<mincredit><xsl:value-of select="."/></mincredit><xsl:text> credit hour</xsl:text></xsl:if>
<xsl:if test=". &gt; 1">
<mincredit><xsl:value-of select="."/></mincredit><xsl:text> credit hours</xsl:text></xsl:if>
</xsl:template>

<xsl:template match="Section/CRSMAXCRED1[string-length() != 0]">
<xsl:text> to </xsl:text><maxcredits><xsl:value-of select="normalize-space(.)" /></maxcredits><xsl:text> credit hours</xsl:text>
</xsl:template>

</xsl:stylesheet>

このスタイルシートは、クラスが最小単位と最大単位の両方を表示するまで、私が望むものを生成し、次の表示を取得します:「1 単位時間から 4 単位時間」

どんな助けでも大歓迎です。

4

1 に答える 1

0

次のようなことをお勧めします。

  <xsl:template match="CrystalReport">
    ...
    <xsl:apply-templates select="Section" mode="credits"/>

  </xsl:template>

  <xsl:template match="Section" mode="credits">
    <xsl:apply-templates select="CRSMINCRED1" />
    <xsl:text> credit hour</xsl:text>
    <xsl:apply-templates select="CRSMINCRED1[. != 1]" mode="pluralize" />
  </xsl:template>

  <xsl:template match="Section[normalize-space(CRSMAXCRED1)]" mode="credits">
    <xsl:apply-templates select="CRSMINCRED1" />
    <xsl:text> to </xsl:text>
    <xsl:apply-templates select="CRSMAXCRED1" />
    <xsl:text> credit hour</xsl:text>
    <xsl:apply-templates select="CRSMAXCRED1[. != 1]" mode="pluralize"/>
  </xsl:template>

  <xsl:template match="CRSMINCRED1">
    <mincredit>
      <xsl:value-of select="." />
    </mincredit>
  </xsl:template>

  <xsl:template match="CRSMAXCRED1">
    <maxcredit>
      <xsl:value-of select="." />
    </maxcredit>
  </xsl:template>

  <xsl:template match="*" mode="pluralize">
    <xsl:text>s</xsl:text>
  </xsl:template>
于 2013-02-12T06:09:58.660 に答える