【问题标题】:XML and XSL connectionXML 和 XSL 连接
【发布时间】:2011-02-14 18:13:42
【问题描述】:

XML 和 XSL 文件之间存在问题。在 XML 文件中,有一些元素,如
*

Stud I
CMPE471
CMPE412
CMPE100



螺柱 II
CMPE471
CMPE412


我的名字
DESC I



NAME II
DESC II



NAME III
DESC III


在 XSL 文件中,我想到达我指定“courseCode”的“description”元素。
输出应该是这样的,
1. Stud我
     一个。 CMPE471 描述 I
     b. CMPE412 描述 II
     c. CMPE100 描述 III

2.螺柱 II
     a. CMPE471 描述 I
     b. CMPE412 描述 II


在 XSL 文件中,我尝试写一些东西:












    1. //问题
      //问题
      //问题


谢谢。

【问题讨论】:

  • 你应该缩进你的代码,让它看起来像代码。此外,结束 标记丢失。

标签: xml xslt


【解决方案1】:

请参阅下面的 XSLT 1.0 和 2.0 解决方案。您的代码中的问题是:

<xsl:value-of select="description [@courseCode = text()]"/>

这意味着您正在寻找元素description,其属性courseCode 与其文本值相同。我所做的是将课程代码保存在一个变量中,并检查属性与此变量相同的course 元素。

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
  <xsl:output indent="yes" />

  <xsl:template match="/">
    <ol>
      <xsl:for-each select="/school/student">
        <xsl:sort data-type="text" order="ascending" select="name" />
        <li>
          <xsl:value-of select="name" />
          <ol type="a">
            <xsl:for-each select="takes">
              <xsl:sort data-type="text" select="." order="ascending" />
              <li>
                <xsl:variable name="coursecode" select="." />
                <xsl:value-of select="concat('(',.,') ')" />
                <xsl:for-each select="/school/course[@courseCode = $coursecode]">
                  <xsl:value-of select="description" />
                </xsl:for-each>

              </li>
            </xsl:for-each>
          </ol>
        </li>
      </xsl:for-each>
    </ol>
  </xsl:template>
</xsl:stylesheet> 

【讨论】:

  • 我试过你的代码,但描述已经没有出现。只是课程代码和(课程代码)出现了。 =>CMPE352 (CMPE351)
猜你喜欢
  • 2013-11-30
  • 1970-01-01
  • 2012-10-25
  • 2012-11-19
  • 1970-01-01
  • 1970-01-01
  • 2023-04-06
  • 2011-11-28
  • 1970-01-01
相关资源
最近更新 更多