-1

这是我正在使用的...

<response code="OK">
      <enrollments>
           <enrollment enddate="9999-12-31T00:00:00Z" startdate="1753-01-01T00:00:00Z" status="1" flags="2228225" guid="a469dd60-8350-4749-8281-7772b6798bcc" reference="MajorMinor.109457483" domainid="616401" entityid="6557156" userid="1554956" id="6557282">
-                <data>
-                   <status>
                        <performance code="2" signal="Red"/><pace signal="Green"/>
                    </status>
                </data>
                <user guid="a992267a-a2ca-4e0c-a8d1-447d0243a4d8" reference="109457483" id="1554956" lastlogindate="1753-01-01T00:00:00Z" email="bak05016@thisone.edu" username="rbaker4" userspace="Thisone" lastname="Baker" firstname="Ryan"/>
                   <domain id="616401" name="This one"/>
-             <grades seconds="0" complete="1" passingscore="0.7" letter="F" possible="100" achieved="45">
-               <items>
                   <item title="" categoryid="1" periodid="0" itemid="DEFAULT"/>
                   <item title="Test 1" categoryid="1" periodid="0" itemid="JECIY"/>
                   <item title="This test will be fun" status="261" letter="F" possible="100" achieved="10" categoryid="1" periodid="0" itemid="7I673" duedate="9999-12-31T23:59:59.9999999Z" scoreddate="2013-03-05T23:31:43.653Z" responseversion="4"/>
                   <item title="Do this homework recieve credit" status="261" letter="B" possible="100" achieved="80" categoryid="1" periodid="0" itemid="39AM7" duedate="9999-12-31T23:59:59.9999999Z" scoreddate="2013-03-07T16:54:08.033Z" responseversion="1"/>
             </items>
-        <categories>
             <category id="1" name="Include" letter="F" possible="200" achieved="90"/><category id="0" name="Exclude" possible="0" achieved="0"/>
         </categories>
     </grades>
   </enrollment>
 </enrollments>
</response code>

因此,我正在使用此代码并使用以下代码运行 XSLT 翻译。

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" />

<xsl:template match="/">

<Enrollments xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  xsi:noNamespaceSchemaLocation="results.xsd">
      <xsl:for-each select="response/enrollments/enrollment">
      <Enrollment>
        <FirstName>
          <xsl:value-of select="user/@firstname"/>
        </FirstName>
        <LastName> 
          <xsl:value-of select="user/@lastname"/>
        </LastName>
        <ID>
          <xsl:value-of select="user/@id"/>
        </ID>
        <Email>
          <xsl:value-of select="user/@email"/>
        </Email>
        <Grade>
          <xsl:value-of select="grades/@achieved"/>
        </Grade>
        <Assignments>
          <xsl:value-of select="grades/items/item/@title"/>
            </xsl:for-each>
        </Assignments>
      </Enrollment>
      </xsl:for-each>
    </Enrollments>
</xsl:template>
</xsl:stylesheet>

我的问题是 xslt 中的 assignments 标记返回来自 xml 数据的已知结果。我需要一种方法来让它返回分数等级的信息。在某种程度上,对于每个项目,将在表中创建一个新列,列标题是分配 ex 的名称。“做这个作业获得学分”然后表格的内容就是他们得分的成绩。我正在使用的原始 xml 文档大约有 4000 行,我们需要对其进行翻译,以便以可用的格式将其放入我们的数据库中。

4

1 回答 1

0

Perhaps you are looking for something like this for your XSLT inside the Assignments element?

<xsl:for-each select="grades/items/item">
  <Assignment>
    <Title><xsl:value-of select="@title"/></Title>
    <Grade><xsl:value-of select="@achieved"/></Grade>
  </Assignment>
</xsl:for-each>
于 2013-03-08T05:46:13.497 回答