Xml 基于元素值更改结果显示

Xml 基于元素值更改结果显示,xml,xslt,Xml,Xslt,我有包含大学课程信息的XML。课程按标题、课程号和总学分显示 我的XSLT按学习领域对数据进行分组,然后按课程编号列出课程,并提供课程说明和总学分数。一切正常,但我想调整学分的最终显示 每门课至少有1-4学分。有些课程有最高学分 我的XSLT提取最小信用和最大信用(如果存在) 然后,XSLT构建最终显示,使其显示为以下内容之一: 当类数据仅具有功能时,显示如下所示: “1学时” “2学时” “3学时” “4学时” 当类数据同时显示和时,显示如下: “1至4学时。” 除了第一件,一切都好。当课程只

我有包含大学课程信息的XML。课程按标题、课程号和总学分显示

我的XSLT按学习领域对数据进行分组,然后按课程编号列出课程,并提供课程说明和总学分数。一切正常,但我想调整学分的最终显示

每门课至少有1-4学分。有些课程有最高学分

我的XSLT提取最小信用
和最大信用
(如果存在)

然后,XSLT构建最终显示,使其显示为以下内容之一:

当类数据仅具有
功能时,显示如下所示: “1学时” “2学时” “3学时” “4学时”

当类数据同时显示
时,显示如下: “1至4学时。”

除了第一件,一切都好。当课程只有“1”最低学分而没有最高学分时,我希望显示为:

“1学时”

我试着做一个“变量”和“如果”语句,但没有成功

下面是一些示例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>

CTⅠ的临床应用
诊断医学成像
2511
3.
CTⅡ的临床应用
DMI
诊断医学影像学2
2512
1.
4.
CTⅢ的临床应用
DMI
诊断医学影像学3
2513
1.
下面是我正在尝试使用的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学时”


任何帮助都将不胜感激。

我建议您这样做:

  <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>

...
学分制
到
学分制
s