转换XML命名空间

时间:2015-10-15 01:12:06

标签: xml xslt

我有以下XML。

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="invoice.xsl"?>
<!DOCTYPE invoice [
    <!ELEMENT invoice (company, to:customer, order)>
    <!ATTLIST invoice xmlns:to CDATA #FIXED "http://www.companyltd.co.nz/dtds/">

    <!ELEMENT company (name, address, city, phone, email)>
        <!ELEMENT name (#PCDATA)>
        <!ELEMENT address (#PCDATA)>
        <!ELEMENT city (#PCDATA)>
        <!ELEMENT phone (#PCDATA)>
        <!ELEMENT email (#PCDATA)>

    <!ELEMENT to:customer (to:name, to:address, to:city, to:phone, to:email)>
        <!ELEMENT to:name (#PCDATA)>
        <!ELEMENT to:address (#PCDATA)>
        <!ELEMENT to:city (#PCDATA)>
        <!ELEMENT to:phone (#PCDATA)>
        <!ELEMENT to:email (#PCDATA)>

    <!ELEMENT order (item+)>
        <!ELEMENT item (id, description, qty, unit-price, total)>
            <!ELEMENT id (#PCDATA)>
            <!ELEMENT description (#PCDATA)>
            <!ELEMENT qty (#PCDATA)>
            <!ELEMENT unit-price (#PCDATA)>
            <!ELEMENT total (#PCDATA)>
]>
<invoice xmlns:to="http://www.companyltd.co.nz/dtds/">
    <company>
        <name>Company Ltd</name>
        <address>111 Placeholder Street</address>
        <city>Hamilton</city>
        <phone>078433411</phone>
        <email>sales@companyltd.co.nz</email>
    </company>

    <to:customer>
        <to:name>Duncan Palmer</to:name>
        <to:address>111 Reee Street</to:address>
        <to:city>Lofton</to:city>
        <to:phone>8133333</to:phone>
        <to:email>duncanrp15@live.com</to:email>
    </to:customer>

    <order>
        <item>
            <id>1</id>
            <description>Black Socks</description>
            <qty>5</qty>
            <unit-price>5</unit-price>
            <total>25</total>
        </item>
    </order>
</invoice>

我正在尝试将to:customers元素转换为我的xsl页面。我试过用这个..

<xsl:value-of select="//to:customer//to:name"/>

然而,这只会引发错误加载样式表:发生了未知错误()&#39;错误。

引用在XSL中使用命名空间的XML的正确方法是什么?

0 个答案:

没有答案