我一直在这个项目上工作几天。该任务让我创建一个基于XML文件并基于DTD文件的XSL样式表。一旦我最终获得了XLT文件来验证(我希望我做的一切都正确),我试了几个小时才用XML生成结果文档,但没有运气。我下载了教科书中推荐的Saxon,但即使我提取了文件等,但仍然收到错误消息。有没有更简单的方法来生成结果XML文档?我也需要确保验证。当Saxon不适合我时,如何生成结果文档?
这里是源代码:
DTD file
<!ELEMENT customers (customer)*>
<!ELEMENT customer (order)>
<!ATTLIST customer id CDATA #IMPLIED>
<!ELEMENT order (qty, date, amount)>
<!ATTLIST order orderid CDATA #IMPLIED>
<!ELEMENT qty (#PCDATA)>
<!ELEMENT date (#PCDATA)>
<!ELEMENT amount (#PCDATA)>
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0"
\t xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
\t <xsl:output method="xml"
\t \t doctype-system="customers.dtd"
\t \t encoding="UTF-8"
\t \t indent="yes" />
\t \t
<xsl:template match="/">
<xsl:comment>
\t Author: Paulina Crawford
\t Date: 10/10/2015
\t </xsl:comment>
\t
<xsl:element name="customers">
<xsl:apply-templates
\t select="orders/order">
<xsl:sort select="custid" />
</xsl:apply-templates>
</xsl:element>
<xsl:apply-templates select="order" />
<xsl:element name="customer">
\t <xsl:attribute name="id">
\t <xsl:value-of select="custid" />
\t </xsl:attribute>
\t <xsl:element name="order">
\t <xsl:value-of select="@orderid/id" />
\t <xsl:value-of select="@qty" />
\t <xsl:value-of select="@date" />
\t <xsl:value-of select="@amount" />
\t </xsl:element>
<xsl:value-of select="custid" />
</xsl:element>
</xsl:template>
</xsl:stylesheet>
<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="clist.xsl" ?>
<orders>
<order id="OR3124" qty="1" custid="CUST204">
<date>5/1/2017</date>
<amount>$108.24</amount>
</order>
<order id="OR3125" qty="2" custid="CUST117">
<date>5/1/2017</date>
<amount>$78.21</amount>
</order>
<order id="OR3126" qty="1" custid="CUST311">
<date>5/1/2017</date>
<amount>$45.93</amount>
</order>
<order id="OR3127" qty="4" custid="CUST091">
<date>5/2/2017</date>
<amount>$68.21</amount>
</order>
<order id="OR3128" qty="1" custid="CUST137">
<date>5/2/2017</date>
<amount>$117.24</amount>
</order>
<order id="OR3129" qty="1" custid="CUST128">
<date>5/3/2017</date>
<amount>$75.68</amount>
</order>
<order id="OR3130" qty="2" custid="CUST083">
<date>5/3/2017</date>
<amount>$58.93</amount>
</order>
<order id="OR3131" qty="1" custid="CUST304">
<date>5/3/2017</date>
<amount>$112.25</amount>
</order>
</orders>
如果任何人都可以请提供任何帮助,我将永远感激......
更新的代码:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml"
\t doctype-system="customers.dtd"
\t encoding="ISO-8859-1"
\t indent="yes" />
\t
<xsl:template match="/">
<xsl:element name="customers">
<xsl:apply-templates
\t select="orders/order">
<xsl:sort select="custid" />
</xsl:apply-templates>
</xsl:element>
<xsl:apply-templates select="order">
<xsl:element name="customer">
<xsl:attribute name="id">
<xsl:value-of select="@custid" />
</xsl:attribute>
<xsl:element name="order">
<xsl:attribute name="orderid">
<xsl:value-of select="@id" />
<xsl:element name="qty">
<xsl:value-of select="@qty" />
<xsl:element name="date">
<xsl:value-of select="date" />
<xsl:element name="amount">
<xsl:value-of select="amount" />
</xsl:element>
<xsl:value-of select="custid" />
</xsl:templates>
</xsl:stylesheet>
如果您不告诉我们错误消息是什么,告诉我们您收到错误消息是毫无意义的。此外,您提交的样式表代码中没有调用xsl:result-document。所以我们完全不知道你做错了什么。 –