当我尝试运行xml文件时,浏览器显示消息加载样式表时出错:失败分析XSLT样式表



正如我在上面的标题中所描述的,我不知道哪里出了问题,也不知道浏览器(firefox、IE)为什么会向我显示此消息(加载样式表时出错:失败分析XSLT样式表)。我将在下面发布xml文件和xsl文件。

exam.xml

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?xml-stylesheet type="text/xsl" href="exam.xsl"?>
<Exam>
    <Title>XML_Master_Exam</Title>
    <Information>
        <ExamName ExamNumber="I10-001">XML Master:Basic</ExamName>
        <ExamTime>60_Minutes</ExamTime>
        <Qeustions>50</Qeustions>
        <MinimumPass>at_least_70% correct</MinimumPass>
    </Information>
    <Information>
        <ExamName ExamNumber="I10-002">XML Master:Professional</ExamName>
        <ExamTime>90_Minutes</ExamTime>
        <Qeustions>40</Qeustions>
        <MinimumPass>at_least_60% correct</MinimumPass>
    </Information>
</Exam>

exam.xsl

<?xml version="1.0" encoding="UTF-8"?>
<xsl:transform version="1.0" xmlns:xsl="http://www.w3.org/1999/XMLTransform">
<xsl:template match="/">
    <test_info>
        <xsl:apply-templates select="//MinimumPass"/>
    </test_info>
</xsl:template>
<xsl:template match="MinimumPass">
    <test_no>
        <xsl:value-of select="../ExamName/@ExamNumber"/>
    </test_no>
</xsl:template>
</xsl:transform>

xsl的命名空间错误。您需要使用http://www.w3.org/1999/XSL/Transform:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:transform version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
    <test_info>
        <xsl:apply-templates select="//MinimumPass"/>
    </test_info>
</xsl:template>
<xsl:template match="MinimumPass">
    <test_no>
        <xsl:value-of select="../ExamName/@ExamNumber"/>
    </test_no>
</xsl:template>
</xsl:transform>

最新更新