php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #50280 XSLT generates strange result
Submitted: 2009-11-24 09:36 UTC Modified: 2009-12-02 01:00 UTC
From: jiangcat at gmail dot com Assigned:
Status: No Feedback Package: XSLT related
PHP Version: 5.2.11 OS: Centos 5.2
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
MUST BE VALID
Solve the problem:
20 + 36 = ?
Subscribe to this entry?

 
 [2009-11-24 09:36 UTC] jiangcat at gmail dot com
Description:
------------
XSLT processor occasionally generates improper result with the XML and XSL data inputted. Even worse, it happens with out any sign or regular operation, which means I can't reproduce this bug. With the same XML + XSL, it gives a perfect result sometimes, but occationally, a buggy result.

The reproduce code is just an idea of what's happening, cuz the actual code I'm running is way too long to submit here. Please ask for it if you could identify this as a BUG, and I'll submit further info.

Reproduce code:
---------------
XML:
...
<root>
  <a>1</a>
  <b>2</b>
</root>
...
XSL:
...
<script type="text/javascript">
<for-each select="/root/*">
  SomeHash.set('<xsl:value-of select="name()" />', <xsl:value-of
select="." />);
</for-each>
</script>
...

Expected result:
----------------
<script type="text/javascript">
  SomeHash.set('a', 1);
  SomeHash.set('b', 2);
</script>

Actual result:
--------------
The result could be such a mass SOMETIMES:
<script type="text/javascript">
  SomeHash.set('a', 1b2;
</script>

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-11-24 13:31 UTC] rasmus@php.net
It would help both you and us if you provided an actual working reproduce script.  It would help you catch obvious mistakes like the fact that you forgot the xsl namespace on the for-each tags there.

I wrote a script to see if I could reproduce your problem:

<?php
$xml = <<<EOB
<root>
  <a>1</a>
  <b>2</b>
</root>
EOB;
$xsl = <<<EOB
<xsl:stylesheet version="1.0" 
              xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                  xmlns="http://www.w3.org/TR/xhtml1/strict">
<xsl:template match="/">
<script type="text/javascript">
<xsl:for-each select="/root/*">
  SomeHash.set('<xsl:value-of select="name()" />', <xsl:value-of select="." />);
</xsl:for-each>
</script>
</xsl:template>
</xsl:stylesheet>
EOB;
$x = DOMDocument::loadXML($xml);

$xslt = new XSLTProcessor();
$s = new DOMDocument();
$s->loadXML($xsl, LIBXML_NOCDATA);
$xslt->importStylesheet($s);
echo $xslt->transformToXML($x); 

And the output of this script for me is:

<?xml version="1.0"?>
<script xmlns="http://www.w3.org/TR/xhtml1/strict" type="text/javascript">
  SomeHash.set('a', 1);

  SomeHash.set('b', 2);
</script>

which seems correct.  Can you verify that you get the same output?
 [2009-12-02 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Jun 16 19:01:30 2024 UTC