Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XSL with PHP DOM

Status
Not open for further replies.

Cilsh

Programmer
Sep 10, 2007
1
SE
I ran in to a problem, with making XSL and making it print.
It's supposed to print <title>(with a href) and then text in html.

The PHP-code:

<?
$dom_xml = new DOMDocument();
$dom_xsl = new DOMDocument();
$xslt = new XSLTProcessor();
$dom_xml->load('dump.xml');
$dom_xsl->load('index-rss.xsl');
$xslt->importStylesheet($dom_xsl);
echo $xslt->transformToXML($dom_xml);
?>

The XML file looks lite this:

<rdf:RDF xmlns:rdf=" xmlns=" xmlns:dc=" xmlns:syn="htt$
<channel rdf:about=" <title>Test</title>
<link> <description>Some desc.</description>
<dc:language>sv</dc:language>
<dc:rights>Copyright </dc:rights>
<dc:date>2007-09-10T09:41:35+01:00</dc:date>
<dc:publisher>Unknown</dc:publisher>
<dc:creator>abuse@domain.tld</dc:creator>
<syn:updatePeriod>daily</syn:updatePeriod>
<syn:updateFrequency>1</syn:updateFrequency>
<syn:updateBase>1970-01-01T00:00+00:00</syn:updateBase>
<items>
<rdf:Seq>
<rdf:li rdf:resource=" /></rdf:Seq>
</items>
<image rdf:resource=" />
</channel>
<item rdf:about="<title>Some title</title>
<link><description>Desc about the item</description>
<dc:creator>XXX YYYY</dc:creator>
<dc:date>2006-10-14T12:00:00+02:00</dc:date>
</item>

<item rdf:about="<title>Some title</title>
<link><description>Desc about the item</description>
<dc:creator>XXX YYYY</dc:creator>
<dc:date>2006-10-14T12:00:00+02:00</dc:date>
</item>

<item rdf:about="<title>Some title</title>
<link><description>Desc about the item</description>
<dc:creator>XXX YYYY</dc:creator>
<dc:date>2006-10-14T12:00:00+02:00</dc:date>
</item>

<item rdf:about="<title>Some title</title>
<link><description>Desc about the item</description>
<dc:creator>XXX YYYY</dc:creator>
<dc:date>2006-10-14T12:00:00+02:00</dc:date>
</item>

</rdf:RDF>

XSL is like:

<xsl:stylesheet xmlns:xsl=" xmlns:rdf=" xmlns:rss=" xmlns:dc=" xmlns:syn=" xmlns=" version="1.0">
<xsl:eek:utput indent="yes"/>
<xsl:template match="rdf:RDF">
<html>
<head>
<title>Output of XSL</title>
</head>
<body>
<h2>
<a href="link"><xsl:apply-templates /></a>
</h2>
Desc here?
</body>
</html>
</xsl:template>

</xsl:stylesheet>

I tried to change rdf:RDF to diffrent, and apply-templates to diffrint, but I really dont get it. Tried to search on the web for how XSL is supposed to grab the diffrent <items> but I never really found/understod how it's supposted to grep the items and loop them and then print <title><link><desc> from my XML output file.

Tried with
<xsl:apply-templates select="/rdf:RDF/rss:item" />
Didnt go so well.

Any help? Would nice if you show where the error is and so on. Thanks.
 
One renderment possible as an illustration. Styling is your own biz. Some changes are more critical, some are less.
[tt]
<xsl:stylesheet xmlns:xsl=" xmlns:rdf=" xmlns:rss=" xmlns:dc=" xmlns:syn=" xmlns=" version="1.0"
[blue]exclude-result-prefixes="rdf rss dc syn"[/blue]>
<xsl:eek:utput [blue]method="html"[/blue] indent="yes"/>

<xsl:template match="rdf:RDF">
<html>
<head>
<title>Output of XSL</title>
</head>
<body>
[red]<!--[/red]
<h2>
<a href="link"><xsl:apply-templates /></a>
</h2>
Desc here?
[red]-->[/red]
[blue]<xsl:apply-templates match="rss:items" />[/blue]
</body>
</html>
</xsl:template>
[blue]
<xsl:template match="rss:item">
<div>
<a href="{rss:link}"><xsl:value-of select="rss:title" /></a>
<xsl:text>&#xa0;&#xa0;</xsl:text>
<xsl:value-of select="rss:description" />
</div>
</xsl:template>
[/blue]
</xsl:stylesheet>
[/tt]
 
Correction
The corresponding line should sure be read like this. My error!
[tt] <xsl:apply-templates [red]select[/red]="rss:items" />[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top