&reftitle.examples;
Example collection.xml and collection.xsl files
Many examples in this reference require both an XML and an XSL file.
We will use collection.xml and
collection.xsl that contains the following:
collection.xml
Fight for your mind
Ben Harper
1995
Electric Ladyland
Jimi Hendrix
1997
]]>
collection.xsl
Hey! Welcome to 's sweet CD collection!
by -
]]>
Error handling with libxml error handling functions
libxml offers a number of functions for handling errors, which can be
employed to capture and deal with errors in XSLT processing.
fruits.xml
A valid XML file.
Apple
Banana
Cherry
]]>
fruits.xsl
Contains an invalid select expression.
]]>
Collating and printing errors
The example below captures and displays libxml errors raised when calling
XSLTProcessor::importStyleSheet with a
stylesheet containing an error.
loadXML('fruits.xml');
$xsldoc->loadXML('fruits.xsl');
libxml_use_internal_errors(true);
$result = $xsl->importStyleSheet($xsldoc);
if (!$result) {
foreach (libxml_get_errors() as $error) {
echo "Libxml error: {$error->message}\n";
}
}
libxml_use_internal_errors(false);
if ($result) {
echo $xsl->transformToXML($xmldoc);
}
?>
]]>
&example.outputs.similar;