PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
raghavan20
DevNet Resident
Posts: 1451 Joined: Sat Jun 11, 2005 6:57 am
Location: London, UK
Contact:
Post
by raghavan20 » Thu Feb 22, 2007 5:19 am
let us say i have a following xml block
Code: Select all
<channel>
<title>Feeds from BBC</title>
<link>http://www.bbc.co.uk</link>
<description>Business feeds from bbc.co.uk</description>
<language>English</language>
<publishedDate>22-02-2007 03:34:02</publishedDate>
</channel>
i want to apply xsl to this. i want to put the title in hyperlink that goes to
http://www.bbc.co.uk
Code: Select all
<table width = '600'>
<tr>
<td>
<a href = "<xsl:value-of select='channel/link' />"> <------------------------------THIS IS WRONG; HOW DO I DO THIS ????
<xsl:value-of select='channel/title' />
</a>
</td>
<td>
Date: <xsl:value-of select='channel/publishedDate' />
</td>
</tr>
<tr>
<td colspan = '2'><xsl:value-of select='channel/description' /></td>
</tr>
</table>
raghavan20
DevNet Resident
Posts: 1451 Joined: Sat Jun 11, 2005 6:57 am
Location: London, UK
Contact:
Post
by raghavan20 » Thu Feb 22, 2007 5:41 am
just a quick doubt. is it possible to use something like css classes and ids.
i am not really interested in writing like this
Code: Select all
<xsl:for-each select="itemList/item">
<tr>
<th style = 'background-color:gray'><xsl:value-of select="title"/></th>
</tr>
<tr>
<td style = 'background-color:lightblue;'><xsl:value-of select="description"/></td>
</tr>
</xsl:for-each>
volka
DevNet Evangelist
Posts: 8391 Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger
Post
by volka » Thu Feb 22, 2007 9:01 am
class="xyz" is a valid xml attribute. And that's all the processor cares about.
<a href = "<xsl:value-of select='channel/link' />">
You're looking for xsl:attribute
Code: Select all
<?php
$rss = '<rss>
<channel>
<title>Feeds from BBC</title>
<link>http://www.bbc.co.uk</link>
<description>Business feeds from bbc.co.uk</description>
<language>English</language>
<publishedDate>22-02-2007 03:34:02</publishedDate>
</channel>
</rss>';
$xsl = '<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" encoding="iso-8859-1" indent="no"/>
<xsl:template match="channel">
<a>
<xsl:attribute name="href"><xsl:value-of select="link"/></xsl:attribute>
<xsl:value-of select="title"/>
</a>
</xsl:template>
</xsl:stylesheet>';
$dom = DOMDocument::loadxml($xsl);
$proc = new XSLTProcessor;
$proc->importStyleSheet($dom);
$dom = DOMDocument::loadxml($rss);
echo $proc->transformToXML($dom);
?>
raghavan20
DevNet Resident
Posts: 1451 Joined: Sat Jun 11, 2005 6:57 am
Location: London, UK
Contact:
Post
by raghavan20 » Thu Feb 22, 2007 12:24 pm
volka wrote: class="xyz" is a valid xml attribute. And that's all the processor cares about.
<a href = "<xsl:value-of select='channel/link' />">
thanks volka, i understand how to use hyperlink. but can you show me some example of how to CSS classes and ids in CSS document?
volka
DevNet Evangelist
Posts: 8391 Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger
Post
by volka » Thu Feb 22, 2007 1:15 pm
raghavan20 wrote: <a href = "<xsl:value-of select='channel/link' />">
That doesn't work.
raghavan20 wrote: but can you show me some example of how to CSS classes and ids in CSS document?
I don't understand the question. Please explain what you're trying to achieve.
volka
DevNet Evangelist
Posts: 8391 Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger
Post
by volka » Thu Feb 22, 2007 2:05 pm
or the mentioned
<xsl:attribute name="href"><xsl:value-of select="link"/></xsl:attribute>
raghavan20
DevNet Resident
Posts: 1451 Joined: Sat Jun 11, 2005 6:57 am
Location: London, UK
Contact:
Post
by raghavan20 » Mon Feb 26, 2007 7:42 am
that was kewl timvw
volka wrote:
Quote:
<xsl:attribute name="href"><xsl:value-of select="link"/></xsl:attribute>
where do you get this list form such as href, etc ?
raghavan20 wrote:
but can you show me some example of how to CSS classes and ids in CSS document?
I don't understand the question. Please explain what you're trying to achieve.
I was just asking if I were to use CSS for XML styling, how would i use classes and ids that are supported by CSS ?
Kieran Huggins
DevNet Master
Posts: 3635 Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:
Post
by Kieran Huggins » Mon Feb 26, 2007 9:57 am
I don't think you can use classes with xml - and
I think you can only use "id"s if you define an attribute as an id in your DTD.
I know one way for you to find out! (and post what you discover here, would you
)
volka
DevNet Evangelist
Posts: 8391 Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger
Post
by volka » Mon Feb 26, 2007 11:40 am
raghavan20 wrote: volka wrote:
Quote:
<xsl:attribute name="href"><xsl:value-of select="link"/></xsl:attribute>
where do you get this list form such as href, etc ?
I do not understand the question.
raghavan20 wrote: I was just asking if I were to use CSS for XML styling, how would i use classes and ids that are supported by CSS ?
Isn't the output (x)html? Then do and use whatever you can do and use in (x)html.