Please help. I'm a newbie and I'm drastically stuck.
I have a database which stores data in xml format but I want to parse it with xslt to produce the format I want. The problem is I have followed everything on php.net to the letter and yet still I'm nowhere. Please take a look at the code below and tell me where I've gone wrong.
if (! empty($searchword ))
$query = "SELECT aml FROM arguments WHERE aml LIKE '%$searchword%'";
$result = mysql_query($query)
or die ("Query failed");
$line = mysql_fetch_array($result, MYSQL_ASSOC);
// var_dump($line);
// Create an array
$arguments = array( 'xml' => $line);
// Checking if array works
if ( is_array($arguments) )
print "It's an array! ";
// Show contents of an array
print_r ($arguments);
// Create an XSLT processor
$xsltHandler = xslt_create();
// Perform the transformation
$html = xslt_process($xsltHandler, 'arg:xml' , 'sheet1.xsl', NULL, $arguments);
// Detect errors
if (!$html) die ('XSLT processing error: '.xslt_error($xsltHandler));
// Destroy the XSLT processor
xslt_free($xsltHandler);
// Output the resulting HTML
print $html;
The screen returns:
"Warning: Sablotron error on line 1: XML parser error 2: syntex error in /home/httpd/html/ctan/resultworkingcopy2.php on line 88
XSLT processing error: XML parser error 3: syntex error "
WHAT GIVES?
I'm hopelessly lost and would greatly appreciate it if a kind soul would help me out! Cheers and thanks in advance!
<?xml version="1.0" encoding="UTF-8"?>
<ARG>
<SCHEMESET>
<SCHEME>
<NAME>Argument from Position to Know</NAME>
<FORM>
<PREMISE>a is in a position to know whether A is true</PREMISE>
<PREMISE>a asserts that A is true</PREMISE>
<CONCLUSION>A is true</CONCLUSION>
</FORM>
<CQ>Is a in a position to know whether A is true?</CQ>
<CQ>Is a an honest (trustworthy, reliable) source?</CQ>
<CQ>Did a actually assert that A is true?</CQ>
</SCHEME>
</SCHEMESET>
<!-- The Text of the AML-->
<TEXT>If any journalists learn about the invasion, then the newspapers will print the news. And if the newspapers print the news, then the invasion will not be a secret. If the invasion is not a secret, then our troops will not have the advantage of surprise. If we do not have the advantage of surprise, then the enemy will be prepared. And if the enemy is prepared, then we are likely to suffer higher casualties. But no journalists learned about the invasion. Therefore, we are not likely to suffer higher casualties.</TEXT>
<!-- The components of the argument-->
<AU>
<PROP identifier="C" missing="no">
<PROPTEXT offset="367">we are likely to suffer higher casualties</PROPTEXT>
</PROP>
<REFUTATION>
<AU>
<PROP identifier="A" missing="no">
<PROPTEXT offset="468">we are not likely to suffer higher casualties</PROPTEXT>
</PROP>
</AU>
</REFUTATION>
<CA>
<AU>
<PROP identifier="D" missing="no">
<PROPTEXT offset="304">the enemy will be prepared</PROPTEXT>
</PROP>
<CA>
<AU>
<PROP identifier="F" missing="no">
<PROPTEXT offset="202">our troops will not have the advantage of surprise</PROPTEXT>
</PROP>
<CA>
<AU>
<PROP identifier="G" missing="no">
<PROPTEXT offset="171">invasion is not a secret</PROPTEXT>
</PROP>
<LA>
<AU>
<PROP identifier="I" missing="no">
<PROPTEXT offset="0">If any journalists learn about the invasion</PROPTEXT>
</PROP>
<REFUTATION>
<AU>
<PROP identifier="B" missing="no">
<PROPTEXT offset="413"> no journalists learned about the invasion</PROPTEXT>
</PROP>
</AU>
</REFUTATION>
</AU>
<AU>
<PROP identifier="H" missing="no">
<PROPTEXT offset="93">the newspapers print the news</PROPTEXT>
</PROP>
</AU>
</LA>
</AU>
</CA>
</AU>
</CA>
</AU>
</CA>
</AU>
</ARG>
It will be very difficult for you to debug your problem like this.
I would suggest the following.
a) Save the XML into a file in your desktop, say arg.xml
b) Keep the XSL in the same directory, say Sheet1.xsl
c) Add a declaration at top of your XML file, which declares that
Sheet1.xls should be used for this XML file. See any XML-XSL tutorial
on how to add this declaration.
Then, try to open arg.xml using Internet Explorer. It will most probably
give you an error message, indicating the line number where there
is a problem in the XSL file. You can then fix the XSL file or the XML file
and get the combination working, until you get the correct results
in browser.
Once this is working, then you can put your XML in database,
and then try to get the same thing working through the PHP script.
copying it to test.xml and test.xsl it works both with <?xml:stylesheet type="text/xsl" href="test.xsl"?> in IE and php-xslt-functions.
How do you read the data in php?