Andre
Andre

Reputation: 385

XSLT Transformation, wrong Namespace

I try to transform a xml document in PHP with XSLT-Processor, but I can't select anything... I think it is a namespaceproblem. If I start with just a clean <products> the transformation works correct.

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

The Xsl-file:

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

I can't change the inputfile, because it is generated by an other programm.

Andre

Upvotes: 0

Views: 139

Answers (1)

Mark Veenstra
Mark Veenstra

Reputation: 4739

Change your XSLT to use the default namespace from the input XML, like this:

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

Upvotes: 2

Related Questions