XSLT转换,错误的命名空间

时间:2015-06-01 12:45:41

标签: php xml xslt xpath

我尝试使用XSLT-Processor在PHP中转换xml文档,但我无法选择任何内容......我认为这是一个名称空间问题。如果我从一个干净的<?xml version="1.0" encoding="utf-8"?> <products xmlns="http://***.net/schemata/base" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://***.net/schemata/base/products.xsd"> <product ean="4260094730238" eol="false" model="1090017" status="true"> <ean>4260094730238</ean> <eol>false</eol> <group>screens</group> <model>1090017</model> <status>true</status> </product> </products> 开始,转换工作正确。

inputxml:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xsl:output method="xml" encoding="UTF-8" indent="yes"/>
    <xsl:template match="/">
        <ARTICLE>
            <SUPPLIER_AID>
                <xsl:value-of select="products/product/ean" />
            </SUPPLIER_AID>
        </ARTICLE>
    </xsl:template>
</xsl:stylesheet>

Xsl文件:

{{1}}

我无法更改输入文件,因为它是由其他程序生成的。

安德烈

1 个答案:

答案 0 :(得分:1)

将您的XSLT更改为使用输入XML中的默认命名空间,如下所示:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xmlns:my="http://***.net/schemata/base" exclude-result-prefixes="my">
    <xsl:output method="xml" encoding="UTF-8" indent="yes"/>
    <xsl:template match="/">
    <ARTICLE>
        <SUPPLIER_AID>
            <xsl:value-of select="my:products/my:product/my:ean" />
        </SUPPLIER_AID>
    </ARTICLE>
    </xsl:template>
</xsl:stylesheet>
相关问题