php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #40838 Built-in template rule for processing-instruction()|comment() missing
Submitted: 2007-03-16 16:58 UTC Modified: 2007-03-16 17:57 UTC
From: korisu at gmail dot com Assigned:
Status: Not a bug Package: XSLT related
PHP Version: 5.2.1 OS: Windows Vista
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 you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: korisu at gmail dot com
New email:
PHP Version: OS:

 

 [2007-03-16 16:58 UTC] korisu at gmail dot com
Description:
------------
The default (built-in) template for processing instructions and comments is not implemented in the current version of libxslt. The template should be as follows:
  <xsl:template match="processing-instruction()|comment()"/>

This is defined in the W3C recommendation (http://www.w3.org/TR/xslt#built-in-rule).

The files used in the test code can be found here:
  http://scott.trenda.net/xml/php-bug-report/test.php (source pasted to "Reproduce Code" section)
  http://scott.trenda.net/xml/php-bug-report/checkerboard.xml
  http://scott.trenda.net/xml/php-bug-report/checkerboard.xsl
  http://scott.trenda.net/xml/php-bug-report/checkerboard2.xsl

This has been reproduced on Windows Vista, running 5.2.1 through IIS7 (ISAPI), and on Linux running 5.1.2 through Apache 2.0 (http://scott.trenda.net/phpinfo.php).

Reproduce code:
---------------
<?php $xslt = new xsltProcessor; ?>
<div>
  <span>Incorrect transformation:</span>
  <div>
    <?php
      $xslt->importStyleSheet(DOMDocument::load("checkerboard.xsl"));
      echo $xslt->transformToXML(DOMDocument::load("checkerboard.xml"));
    ?>
  </div>
  <span>Correct transformation (built-in stylesheet explicitly defined in checkerboard2.xsl)</span>
  <div>
    <?php
      $xslt->importStyleSheet(DOMDocument::load("checkerboard2.xsl"));
      echo $xslt->transformToXML(DOMDocument::load("checkerboard.xml"));
    ?>
  </div>
</div>

Expected result:
----------------
The first example does not have a template defined for processing instructions and comments; if you view the source, you will see the xml-stylesheet processing instruction from the source, and the test comment following it:
<?xml-stylesheet type="text/xsl" href="xslt/checkerboard.xsl"><!-- Testing comment template -->

The second example has the template explicitly defined as per the W3C Recommendation; its source has neither the xml-stylesheet processing instruction nor the test comment.

Actual result:
--------------
<div>
  <span>Incorrect transformation:</span>
  <div>
    <?xml-stylesheet type="text/xsl" href="xslt/checkerboard.xsl"><!-- Testing comment template --><html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style>
			table { border: 1px solid gray; border-collapse: collapse; }
			td { width: 40px; height: 40px; }
			.cell0 { background-color: black; }
			.cell1 { background-color: white; }
		</style>
</head>
<body><table>
<tr>
<td class="cell0"></td>
<td class="cell1"></td>

<td class="cell0"></td>
<td class="cell1"></td>
<td class="cell0"></td>
<td class="cell1"></td>
<td class="cell0"></td>
<td class="cell1"></td>
</tr>
<tr>
<td class="cell1"></td>
<td class="cell0"></td>
<td class="cell1"></td>
<td class="cell0"></td>
<td class="cell1"></td>
<td class="cell0"></td>
<td class="cell1"></td>
<td class="cell0"></td>
</tr>

<tr>
<td class="cell0"></td>
<td class="cell1"></td>
<td class="cell0"></td>
<td class="cell1"></td>
<td class="cell0"></td>
<td class="cell1"></td>
<td class="cell0"></td>
<td class="cell1"></td>
</tr>
<tr>
<td class="cell1"></td>
<td class="cell0"></td>
<td class="cell1"></td>
<td class="cell0"></td>
<td class="cell1"></td>
<td class="cell0"></td>

<td class="cell1"></td>
<td class="cell0"></td>
</tr>
<tr>
<td class="cell0"></td>
<td class="cell1"></td>
<td class="cell0"></td>
<td class="cell1"></td>
<td class="cell0"></td>
<td class="cell1"></td>
<td class="cell0"></td>
<td class="cell1"></td>
</tr>
<tr>
<td class="cell1"></td>
<td class="cell0"></td>
<td class="cell1"></td>

<td class="cell0"></td>
<td class="cell1"></td>
<td class="cell0"></td>
<td class="cell1"></td>
<td class="cell0"></td>
</tr>
<tr>
<td class="cell0"></td>
<td class="cell1"></td>
<td class="cell0"></td>
<td class="cell1"></td>
<td class="cell0"></td>
<td class="cell1"></td>
<td class="cell0"></td>
<td class="cell1"></td>
</tr>
<tr>

<td class="cell1"></td>
<td class="cell0"></td>
<td class="cell1"></td>
<td class="cell0"></td>
<td class="cell1"></td>
<td class="cell0"></td>
<td class="cell1"></td>
<td class="cell0"></td>
</tr>
</table></body>
</html>
  </div>
  <span>Correct transformation (built-in stylesheet explicitly defined in checkerboard2.xsl)</span>
  <div>

    <html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style>
			table { border: 1px solid gray; border-collapse: collapse; }
			td { width: 40px; height: 40px; }
			.cell0 { background-color: black; }
			.cell1 { background-color: white; }
		</style>
</head>
<body><table>
<tr>
<td class="cell0"></td>
<td class="cell1"></td>
<td class="cell0"></td>
<td class="cell1"></td>
<td class="cell0"></td>
<td class="cell1"></td>
<td class="cell0"></td>
<td class="cell1"></td>

</tr>
<tr>
<td class="cell1"></td>
<td class="cell0"></td>
<td class="cell1"></td>
<td class="cell0"></td>
<td class="cell1"></td>
<td class="cell0"></td>
<td class="cell1"></td>
<td class="cell0"></td>
</tr>
<tr>
<td class="cell0"></td>
<td class="cell1"></td>
<td class="cell0"></td>
<td class="cell1"></td>
<td class="cell0"></td>

<td class="cell1"></td>
<td class="cell0"></td>
<td class="cell1"></td>
</tr>
<tr>
<td class="cell1"></td>
<td class="cell0"></td>
<td class="cell1"></td>
<td class="cell0"></td>
<td class="cell1"></td>
<td class="cell0"></td>
<td class="cell1"></td>
<td class="cell0"></td>
</tr>
<tr>
<td class="cell0"></td>
<td class="cell1"></td>

<td class="cell0"></td>
<td class="cell1"></td>
<td class="cell0"></td>
<td class="cell1"></td>
<td class="cell0"></td>
<td class="cell1"></td>
</tr>
<tr>
<td class="cell1"></td>
<td class="cell0"></td>
<td class="cell1"></td>
<td class="cell0"></td>
<td class="cell1"></td>
<td class="cell0"></td>
<td class="cell1"></td>
<td class="cell0"></td>
</tr>

<tr>
<td class="cell0"></td>
<td class="cell1"></td>
<td class="cell0"></td>
<td class="cell1"></td>
<td class="cell0"></td>
<td class="cell1"></td>
<td class="cell0"></td>
<td class="cell1"></td>
</tr>
<tr>
<td class="cell1"></td>
<td class="cell0"></td>
<td class="cell1"></td>
<td class="cell0"></td>
<td class="cell1"></td>
<td class="cell0"></td>

<td class="cell1"></td>
<td class="cell0"></td>
</tr>
</table></body>
</html>
  </div>
</div>

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-03-16 17:29 UTC] chregu@php.net
it's a libxslt issue, if at all, as you correctly realized by yourself. 
Please complain there, if you really think, it's a bug.

But you have a 
<template match="node()">
matcher, which also matches to processing-instruction() and comment() 
nodes...

If you change that to <template match="*|text()"> everything works like 
expected

 [2007-03-16 17:57 UTC] korisu at gmail dot com
... So it is. Forgot that node() will match processing-instruction() and comment(), and this behavior comes from the <copy> element. Thanks! (and sorry about the bug-file)
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Dec 27 01:01:28 2024 UTC