-2

我不能使用 xPath 来查询我的 xml 文件。我不知道错误在哪里,这是我的架构

<?xml version="1.0" encoding="UTF-8"?>

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://xml.netbeans.org/schema/Manufacturers"
xmlns="http://xml.netbeans.org/schema/Manufacturers"
elementFormDefault="qualified">
<xsd:element name="ManufacturerList">
    <xsd:complexType>
        <xsd:sequence>
            <xsd:element name="Manufacturer" type="manufacturerType" maxOccurs="unbounded" />
        </xsd:sequence>
    </xsd:complexType>
</xsd:element>
<xsd:complexType name="manufacturerType">
    <xsd:sequence>
        <xsd:element name="ManufacturersID" type="xsd:positiveInteger"/>
        <xsd:element name="ManufacturersName" type="xsd:string"/>
    </xsd:sequence>
</xsd:complexType>

这是我使用 marshall 生成 xml 文件后的 xml 文件

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ManufacturerList xmlns="http://xml.netbeans.org/schema/Manufacturers">
<Manufacturer>
    <ManufacturersID>1</ManufacturersID>
    <ManufacturersName>SamSung</ManufacturersName>
</Manufacturer>
<Manufacturer>
    <ManufacturersID>2</ManufacturersID>
    <ManufacturersName>Apple</ManufacturersName>
</Manufacturer>
<Manufacturer>
    <ManufacturersID>3</ManufacturersID>
    <ManufacturersName>Nokia</ManufacturersName>
</Manufacturer>

这是我的 xsl 文件

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
xmlns:manu="http://xml.netbeans.org/schema/Manufacturers" 
exclude-result-prefixes="manu" version="1.0">
<xsl:output method="html"/>
<xsl:template match="/">
    <html>
        <body>
            <xsl:apply-templates/>
        </body>
    </html>
</xsl:template>
<xsl:template match="/">
    <xsl:for-each select="/manu:Manufacturer">
        <li>
            <a href="#">
                <xsl:value-of select="manu:ManufacturersName"/>
            </a>
        </li>
    </xsl:for-each>
</xsl:template>
</xsl:stylesheet>

在运行网页时的jsp文件中,我无法得到我想要的结果。xsl 文件无法使用 xpath 查询读取 xml 文件

4

1 回答 1

0

您必须注册命名空间。看看: php手册

于 2013-06-23T08:49:03.630 回答