Hi all,
I'm trying to do what I thought would be a really simple task in PHP... But these XML attributes are killing me. Following is the code:
[books.xml]
<?xml version="1.0" ?>
<!DOCTYPE books SYSTEM "book.dtd">
<books>
<book>
<status instock="yes"/>
<title >The Grapes of Wrath</title>
<author>John Steinbeck</author>
</book>
<book>
<status instock="yes"/>
<title>The Pearl</title>
<author>John Steinbeck</author>
</book>
<book>
<status instock="yes"/>
<title>PHP de Luxe</title>
<author>Richard Samar, Christian Stocker</author>
</book>
</books>
[books.xsl]
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >
<xsl:output method="html" encoding="iso-8859-1" />
<xsl:template match="/">
<html>
<head></head>
<body>
<xsl:apply-templates select="/books/book"/>
</body>
</html>
</xsl:template>
<xsl:template match="/books/book">
Title: <xsl:value-of select="title"/><br/>
Author: <xsl:value-of select="author"/><br/>
<xsl:attribute name="status"><xsl:value-of select="@instock"/></xsl:attribute>
<hr/>
</xsl:template>
</xsl:stylesheet>
[index.php]
<?php
$dom = new domDocument();
$dom->load("books.xsl");
$proc = new xsltprocessor;
$xsl = $proc->importStylesheet($dom);
// print_r($proc);
$document = new DomDocument();
$document->load("books.xml");
print $proc->transformToXml($document);
//print_r($document);
?>
As you can see, I'm just trying to parse the XML file, and output it. My problem is with the 'status' attribute in the XML file - I cannot for the life of my extract it.
Can another pair of eyes see the error of my ways?
Thanks! m.