php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #44140 XMLNS seem to be ignored for selecting attributes
Submitted: 2008-02-17 05:52 UTC Modified: 2008-02-18 09:53 UTC
From: daniel dot oconnor at gmail dot com Assigned:
Status: Not a bug Package: XSLT related
PHP Version: 5.2.5 OS: Windows
Private report: No CVE-ID: None
 [2008-02-17 05:52 UTC] daniel dot oconnor at gmail dot com
Description:
------------
If an element + attribute are in a namespace, do both need to explicitly referenced with said namespace?

Currently:

//example:Numbers@sequence vs //example:Numbers@example:sequence

Which is the correct behaviour? PHP currently chooses the first.

Reproduce code:
---------------
<?php
/* bug.xsl
<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:example="http://example.com/">

    <xsl:template match="example:Numbers">
        I expect to see 54321 54321 One Two Three Four Five after this point
        <xsl:value-of select="@sequence" />
        <xsl:value-of select="@example:sequence" />
        <xsl:value-of select="." />
    </xsl:template>
</xsl:stylesheet>
*/

/* bug.xml
<?xml version="1.0" encoding="utf-8"?>
<Example xmlns="http://example.com/" xmlns:ex="http://example.com">
    <Numbers ex:sequence="54321" sequence="12345">One Two Three Four Five</Numbers>
</Example>
*/
if (!extension_loaded('xsl')) {
	die("Don't forget to enable to xsl extension");
}

$xml = new DOMDocument;
$xml->load(dirname(__FILE__) . '/bug.xml');

$xsl = new DOMDocument;
$xsl->load(dirname(__FILE__) . '/bug.xsl');

$proc = new XSLTProcessor;
$proc->importStyleSheet($xsl); // attach the xsl rules

print $proc->transformToXML($xml);
?>


Expected result:
----------------
---------- php ----------
<?xml version="1.0"?>

    
        I expect to see 54321 54321 One Two Three Four Five after this point
        5432154321One Two Three Four Five


Output completed (0 sec consumed) - Normal Termination

Actual result:
--------------
---------- php ----------
<?xml version="1.0"?>

    
        I expect to see 54321 54321 One Two Three Four Five after this point
        12345One Two Three Four Five


Output completed (0 sec consumed) - Normal Termination

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-02-17 08:29 UTC] chregu@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

Attributes are never in the default namespace, they have always to be 
declared specifically. See the XML Specs for details
 [2008-02-17 09:46 UTC] daniel dot oconnor at gmail dot com
> Attributes are never in the default namespace, they have always to be 
declared specifically. See the XML Specs for details

So you mean it should have been '//example:Numbers@example:sequence' ? If so, then PHP is choosing the wrong behaviour.
 [2008-02-18 09:53 UTC] chregu@php.net
you should choose the same namespaces....

<Example xmlns="http://example.com/" xmlns:ex="http://example.com">

missing slash :)

And even if it would still be wrong, it's still not a PHP issue, since 
the whole XSLT transformation is done by libxslt.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 07 05:01:29 2024 UTC