ID: 50280
Updated by: [email protected]
Reported By: jiangcat at gmail dot com
-Status: Open
+Status: Feedback
Bug Type: XSLT related
Operating System: Centos 5.2
PHP Version: 5.2.11
New Comment:
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?
Previous Comments:
------------------------------------------------------------------------
[2009-11-24 09:36:57] 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>
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=50280&edit=1