2015-06-01 95 views
0

我尝试使用XSLT处理器在PHP中转换xml文档,但是我无法选择任何东西......我认为这是一个命名空间问题。如果我从一个干净的<products>开始,那么这个转换就是正确的。XSLT转换,错误的命名空间

的inputxml:

<?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> 

的XSL-文件:

<?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> 

我不能改变inputfile中,因为它是由一个其他PROGRAMM生成。

安德烈

回答

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> 
+0

感谢。对我来说很完美。 – Andre