php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #43289 xslt document('') function return just a part of template
Submitted: 2007-11-14 08:23 UTC Modified: 2007-11-14 16:06 UTC
From: maximchick at gmail dot com Assigned:
Status: Not a bug Package: XSLT related
PHP Version: 5.2.5 OS: Gentoo Linux
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: maximchick at gmail dot com
New email:
PHP Version: OS:

 

 [2007-11-14 08:23 UTC] maximchick at gmail dot com
Description:
------------
xsl:document('') function must return contents of the template itself when the argument is empty string, but when i'm trying to modify template DOM document('') returns contents of original xsl loaded by DOMDocument::load() without my modifications.

Reproduce code:
---------------
$ cat /tmp/template.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="text"/>
<xsl:template match="/">
<xsl:for-each select="document('')//xsl:*"><xsl:value-of select="name()"/><xsl:text>
</xsl:text></xsl:for-each>
</xsl:template>
</xsl:stylesheet>

$cat /tmp/template.php
<?php
$xml = new DOMDocument; //empty document (our stylesheet parses itself)
$xml->load('/tmp/template.xsl');

$xsl = new DOMDocument;
$xsl->load('/tmp/template.xsl');

$xpath = new DOMXPath($xsl);
$xpath->registerNamespace('xsl','http://www.w3.org/1999/XSL/Transform');

$xpath->query('//xsl:stylesheet')->item(0)->appendChild($xpath->query('//xsl:template')->item(0)->cloneNode(true));

echo $xsl->saveXML(); //output changed xsl document

$proc = new XSLTProcessor();
$proc->importStylesheet($xsl);

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

Expected result:
----------------
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="text"/>
<xsl:template match="/">
<xsl:for-each select="document('')//xsl:*"><xsl:value-of select="name()"/><xsl:text>
</xsl:text></xsl:for-each>
</xsl:template>
<xsl:template match="/">
<xsl:for-each select="document('')//xsl:*"><xsl:value-of select="name()"/><xsl:text>
</xsl:text></xsl:for-each>
</xsl:template></xsl:stylesheet>
xsl:stylesheet
xsl:output
xsl:template
xsl:for-each
xsl:value-of
xsl:text
xsl:output
xsl:template
xsl:for-each
xsl:value-of
xsl:text

Actual result:
--------------
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="text"/>
<xsl:template match="/">
<xsl:for-each select="document('')//xsl:*"><xsl:value-of select="name()"/><xsl:text>
</xsl:text></xsl:for-each>
</xsl:template>
<xsl:template match="/">
<xsl:for-each select="document('')//xsl:*"><xsl:value-of select="name()"/><xsl:text>
</xsl:text></xsl:for-each>
</xsl:template></xsl:stylesheet>
xsl:stylesheet
xsl:output
xsl:template
xsl:for-each
xsl:value-of
xsl:text

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-11-14 16:06 UTC] rrichards@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

You are either modifying wrong document or don't understand than only 1 template is matched here. Either way the output is exactly as it should be.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 14:01:31 2024 UTC