i installed php-4.3.1 + apache_1.3.27 + libxml2-2.5.6 + Sablot-0.96 + expat-1.95.4 on redhat 7.3 and tried to use xslt_process() function..but i failed.. here are my codes..


------------------ list.xml --------------------

<?xml version="1.0">
<list>
<title>t1</title>
<author>a1</author>
<blurb>b1<blurb>

<title>t2</title>
<author>a2</author>
<blurb>b2<blurb>

<title>t3</title>
<author>a3</author>
<blurb>b3<blurb>
</list>

---------------- list.xsl ------------------------

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<!-- set up the main page container -->
<xsl:template match="/">
<html>
<head>
</head>
<body>
<xsl:apply-templates />
</body>
</html>

</xsl:template>

<!-- look for the list node -->
<xsl:template match="/list" xml:space="preserve">
<h3><font face="Arial">Bestsellers</font></h3>

<!-- iterate through the item nodes under the list node -->

<ul>
<xsl:for-each select="item">
<li>
<font face="Arial"><b><xsl:value-of select="title" /></b> - <xsl:value-of select="author" /></font>

<font face="Arial"><i><xsl:value-of select="blurb" /></i></font>
<p />
</li>
</xsl:for-each>
</ul>

</xsl:template>
</xsl:stylesheet>

---------------- xsl.php -----------------------------

<?php

// set the filenames
$xml_file = "list.xml";
$xslt_file = "list.xsl";

// create the XSLT processor
$xp = xslt_create() or die("Could not create XSLT processor");

// process the two files to get the desired output
if($result = xslt_process($xp, $xml_file, $xslt_file))
{
// print output
echo $result;
}
else
{
// else display error
echo "An error occurred: " . xslt_error($xp) . "(error code " . xslt_errno($xp) . ")";
}

// free the resources occupied by the handler
xslt_free($xp);

?>

and this is the error message..

"An error occurred: XML parser error 4: not well-formed (invalid token)(error code 2)"

where did i go wrong?
thanks for any answer...

    sorry .. a lillte mistake on the code..

    -------list.xml--------------

    <?xml version="1.0">

    <list>
    <item>
    <title>t1</title>
    <author>a1</author>
    <blurb>b1</blurb>
    </item>
    <item>
    <title>t2</title>
    <author>a2</author>
    <blurb>b2</blurb>
    </item>
    <item>
    <title>t3</title>
    <author>a3</author>
    <blurb>b3</blurb>
    </item>
    </list>

      2 years later

      Did you find the problem. I have this problem too.

      Thank you,
      Marcio

        marky_18 wrote:

        sorry .. a lillte mistake on the code..

        That's why the forum software comes with an "edit" button 🙂

        <?xml version="1.0"[b]?[/b]> 

        , perhaps? Without that change, Firefox reports an unclosed token on line 1, column 1. With it, both your XML and XSLT files come through as valid XML.

          Write a Reply...