0

XML に問題があり、そこから使用可能な XML を作成しようとしていますが、XSLT が正しく機能しません。上のセクションは機能していますが、下半分にデータを表示できません。

XML データのサンプルを次に示します。

<crystalreports>
<Group Level="1">
<Group Level="2">
<Group Level="3">
<Details Level="4">
<Section SectionNumber="0">
<ACPGDEGREE1>AAS</ACPGDEGREE1>
<CCD11/>
<ACPGCOMMENTS1>The Accounting program is designed to provide the theoretical and practical background necessary for supervisory and administrative careers in accounting and accounting-related areas. This degree requires a minimum of 64 credits in program requirements, program electives, and general education as listed below.</ACPGCOMMENTS1>
<ICCB1>3203</ICCB1>
<DEPARTMENT12>ACCOU</DEPARTMENT12>
<ACADPROGRAMSID1>ACCOU.AAS</ACADPROGRAMSID1>
<CRSNO1>1150</CRSNO1>
<CRSTITLE11>Managerial Accounting</CRSTITLE11>
<CRSMINCRED1>4.00</CRSMINCRED1>
<ACRBPRINTEDSPEC1/>
<ACPGHOMELANGNOTREQDRSN1>General Education - 12 to 16 (In addition to those listed above)  Total Credits Required - 64 to 70</ACPGHOMELANGNOTREQDRSN1>
</Section>
</Details>
<Details Level="4">
<Section SectionNumber="0">
<ACPGDEGREE1>AAS</ACPGDEGREE1>
<CCD11/>
<ACPGCOMMENTS1>The Accounting program is designed to provide the theoretical and practical background necessary for supervisory and administrative careers in accounting and accounting-related areas. This degree requires a minimum of 64 credits in program requirements, program electives, and general education as listed below.</ACPGCOMMENTS1>
<ICCB1>3203</ICCB1>
<DEPARTMENT12>ACCOU</DEPARTMENT12>
<ACADPROGRAMSID1>ACCOU.AAS</ACADPROGRAMSID1>
<CRSNO1>2205</CRSNO1>
<CRSTITLE11>Federal Taxation I</CRSTITLE11>
<CRSMINCRED1>3.00</CRSMINCRED1>
<ACRBPRINTEDSPEC1/>
<ACPGHOMELANGNOTREQDRSN1>General Education - 12 to 16 (In addition to those listed above)  Total Credits Required - 64 to 70</ACPGHOMELANGNOTREQDRSN1>
</Section>
</Details>
<GroupFooter>
<Section SectionNumber="0"/>
</GroupFooter>
</Group>
<GroupFooter>
<Section SectionNumber="0"/>
</GroupFooter>
</Group>
<GroupFooter>
<Section SectionNumber="0"/>
</GroupFooter>
</Group>
<Group Level="1">
<Group Level="2">
<Group Level="3">
<Details Level="4">
<Section SectionNumber="0">
<ACPGDEGREE1/>
<CCD11>ACAC</CCD11>
<ACPGCOMMENTS1>The Accounting certificate requires a minimum 32 credits in the courses listed below.    </ACPGCOMMENTS1>
<ICCB1>4207</ICCB1>
<DEPARTMENT12>ACCOU</DEPARTMENT12>
<ACADPROGRAMSID1>ACCOU.CER</ACADPROGRAMSID1>
<CRSNO1>1221</CRSNO1>
<CRSTITLE11>Introduction to Spreadsheets</CRSTITLE11>
<CRSMINCRED1>3.00</CRSMINCRED1>
<ACRBPRINTEDSPEC1/>
<ACPGHOMELANGNOTREQDRSN1/>
</Section>
</Details>
<Details Level="4">
<Section SectionNumber="0">
<ACPGDEGREE1/>
<CCD11>ACAC</CCD11>
<ACPGCOMMENTS1>The Accounting certificate requires a minimum 32 credits in the courses listed below.   </ACPGCOMMENTS1>
<ICCB1>4207</ICCB1>
<DEPARTMENT12>ACCOU</DEPARTMENT12>
<ACADPROGRAMSID1>ACCOU.CER</ACADPROGRAMSID1>
<CRSNO1>1150</CRSNO1>
<CRSTITLE11>Managerial Accounting</CRSTITLE11>
<CRSMINCRED1>4.00</CRSMINCRED1>
<ACRBPRINTEDSPEC1/>
<ACPGHOMELANGNOTREQDRSN1/>
</Section>
</Details>
<Details Level="4">
<Section SectionNumber="0">
<ACPGDEGREE1/>
<CCD11>ACAC</CCD11>
<ACPGCOMMENTS1>The Accounting certificate requires a minimum 32 credits in the courses listed below.</ACPGCOMMENTS1>
<ICCB1>4207</ICCB1>
<DEPARTMENT12>ACCOU</DEPARTMENT12>
<ACADPROGRAMSID1>ACCOU.CER</ACADPROGRAMSID1>
<CRSNO1>1175</CRSNO1>
<CRSTITLE11>Microcomputer Accounting</CRSTITLE11>
<CRSMINCRED1>2.00</CRSMINCRED1>
<ACRBPRINTEDSPEC1/>
<ACPGHOMELANGNOTREQDRSN1/>
</Section>
</Details>
<GroupFooter>
<Section SectionNumber="0"/>
</GroupFooter>
</Group>
<GroupFooter>
<Section SectionNumber="0"/>
</GroupFooter>
</Group>
<GroupFooter>
<Section SectionNumber="0"/>
</GroupFooter>
</Group>
</crystalreports>

XSLT は次のとおりです。

<?xml version="1.0"?><!-- DWXMLSource="STX049 Course Catalog Parsed.xml" -->
<!DOCTYPE xsl:stylesheet>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="no"/>

<xsl:key name="degrees-by-title" match="Group/Group/Group/Details" use="Section/DEPTSDESC1" />

<xsl:template match="CrystalReport">

<crystalreports>
<xsl:for-each select="Group/Group/Group/Details[count(. | key('degrees-by-title', Section/DEPTSDESC1)[1]) = 1]">
<department>
<Degreetitle><xsl:value-of select="Section/ACPGDEGREE1"/></Degreetitle><xsl:text> DEGREE 
</xsl:text><DegreeDesc><xsl:value-of select="Section/ACPGCOMMENTS1"/></DegreeDesc><xsl:text> 
ICCB Code </xsl:text><ICCBcode><xsl:value-of select="Section/ICCB1"/></ICCBcode><xsl:text> | Field of Study     Code: </xsl:text><ProgramID><xsl:value-of select="Section/ACADPROGRAMSID1"/></ProgramID><xsl:text> 
Program Requirements
</xsl:text>
<xsl:for-each select="key('degrees-by-title', Section/DEPTSDESC1)">
<xsl:sort select="Section/DEPARTMENT12" />
<Details> 
<class><deptname><xsl:value-of select="Section/DEPARTMENT12"/></deptname><xsl:text> </xsl:text><courseno>    <xsl:value-of select="Section/CRSNO1"/></courseno><classname><xsl:value-of select="Section/CRSTITLE11"/>    </classname><xsl:text> </xsl:text><classcredit><xsl:value-of select="Section/CRSMINCRED1"/></classcredit>    </class><xsl:text>
</xsl:text> 
</Details>
</xsl:for-each>
</department><xsl:text>
</xsl:text>
</xsl:for-each>
</crystalreports>
</xsl:template>
</xsl:stylesheet>

上半分は機能しますが、下のループでデータを取得できず、理由がわかりません。

基本的に、私はこのように終わらせようとしています:

<crystalreports>
<department>
<Degreetitle>ACPGDEGREE1</Degreetitle> DEGREE 
<DegreeDesc>ACPGCOMMENTS1</DegreeDesc>
ICCB Code <ICCBcode>ICCB1</ICCBcode> | Field of Study  Code: <ProgramID>ACADPROGRAMSID1</ProgramID>

Program Requirements
<xsl:for-each select="key('degrees-by-title', Section/DEPTSDESC1)">
<xsl:sort select="Section/DEPARTMENT12" />
<Details> 
<class><deptname>DEPARTMENT12</deptname><courseno>CRSNO1</courseno><classname>CRSTITLE11</classname <classcredit>CRSMINCRED1</classcredit></class>
</Details>
</xsl:for-each>
</department>
</xsl:for-each>
</crystalreports>
4

1 に答える 1

0

XML サンプルの複数のルートが OP の間違いであると仮定すると、解決策は以下のとおりです。

間違っていたのは次のとおりです。

  • xsl:template match="CrystalReport"一致する XML 要素パスに置き換える必要があります (CrystalReportソース XML にはタグがありません。
  • degrees-by-titleキーが存在しないノード名を使用しました。

解決

<?xml version="1.0"?>
<!-- DWXMLSource="STX049 Course Catalog Parsed.xml" -->
<!DOCTYPE xsl:stylesheet>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="xml" indent="no"/>

  <xsl:key name="degrees-by-title" match="Group/Group/Group/Details" use="Section" />

  <xsl:template match="Group/Group/Group">
    <crystalreports>
      <xsl:for-each select="Details[count(. | key('degrees-by-title', Section/DEPTSDESC1)[1]) = 1]">
        <department>
          <Degreetitle>
            <xsl:value-of select="Section/ACPGDEGREE1"/>
          </Degreetitle>
          <xsl:text> DEGREE 
</xsl:text>
          <DegreeDesc>
            <xsl:value-of select="Section/ACPGCOMMENTS1"/>
          </DegreeDesc>
          <xsl:text> 
ICCB Code </xsl:text>
          <ICCBcode>
            <xsl:value-of select="Section/ICCB1"/>
          </ICCBcode>
          <xsl:text> | Field of Study     Code: </xsl:text>
          <ProgramID>
            <xsl:value-of select="Section/ACADPROGRAMSID1"/>
          </ProgramID>
          <xsl:text> 
Program Requirements
</xsl:text>
          <xsl:for-each select="key('degrees-by-title', Section)">
            <xsl:sort select="Section/DEPARTMENT12" />
            <Details>
              <class>
                <deptname>
                  <xsl:value-of select="Section/DEPARTMENT12"/>
                </deptname>
                <xsl:text> </xsl:text>
                <courseno>
                  <xsl:value-of select="Section/CRSNO1"/>
                </courseno>
                <classname>
                  <xsl:value-of select="Section/CRSTITLE11"/>
                </classname>
                <xsl:text> </xsl:text>
                <classcredit>
                  <xsl:value-of select="Section/CRSMINCRED1"/>
                </classcredit>
              </class>
              <xsl:text>
</xsl:text>
            </Details>
          </xsl:for-each>
        </department>
        <xsl:text>
</xsl:text>
      </xsl:for-each>
    </crystalreports>
  </xsl:template>
</xsl:stylesheet>
于 2012-12-09T20:36:11.343 に答える