Page 1 of 1
XSL formatting
Posted: Thu Feb 22, 2007 5:19 am
by raghavan20
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>
Posted: Thu Feb 22, 2007 5:41 am
by raghavan20
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>
Posted: Thu Feb 22, 2007 9:01 am
by volka
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);
?>
Posted: Thu Feb 22, 2007 12:24 pm
by raghavan20
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?
Posted: Thu Feb 22, 2007 1:15 pm
by volka
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.
Posted: Thu Feb 22, 2007 1:58 pm
by timvw
If i understand well, it's the same problem as described in:
http://www.timvw.be/value-of-in-an-attribute/.
For you the answer would be:
<a href ="{channel/link}">
Posted: Thu Feb 22, 2007 2:05 pm
by volka
or the mentioned
<xsl:attribute name="href"><xsl:value-of select="link"/></xsl:attribute>

Posted: Mon Feb 26, 2007 7:42 am
by raghavan20
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 ?
Posted: Mon Feb 26, 2007 9:57 am
by Kieran Huggins
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

)
Posted: Mon Feb 26, 2007 11:40 am
by volka
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.