Datasheet
Williams c01.tex V3 - 07/31/2009 2:53pm Page 19
Chapter 1: First Steps with XSLT
<channel>
<xsl:attribute name
=
"rdf:about">
<xsl:value-of>feed/link/@href<.xsl:value-of>
</xsl:attribute>
...
</channel>
Completing the Feed Elements
Adding a title is straightforward, again using the element
<xsl:value-of>
; you could also have used
<xsl:copy-of>
because the elements are identical in each vocabulary:
<title>
<xsl:value-of select
=
"feed/title"/>
</title>
There’s nothing you can use to fill the
<description>
element except perhaps the feed’s subtitle, but that
might not be a good idea because it is optional in the Atom schema.
Next you come to the
<link>
element in the RSS feed ... but wait — you’ve just used the required value
in the
rdf:about
attribute. Let’s backtrack and create a reusable template variable
$feedurl.
You can also refine the selection to choose the link that has the
rel
attribute set to
‘self’
, because there
are two link elements in the source. To do this you use a predicate inside square brackets:
"[]"
.You’ll
learn more about predicates in the next chapter. Change the code to look like this:
<channel>
<xsl:variable name
=
"feedurl" select
=
"feed/link[@rel
=
’self’]/@href"/>
<xsl:attribute name
=
"rdf:about">
<xsl:value-of select
=
"$feedurl"/>
</xsl:attribute>
<title>
<xsl:value-of select
=
"feed/title"/>
</title>
<link><xsl:value-of select
=
"$feedurl"/></link>
...
</channel>
Item Listing
To create an item listing to act as a table of contents, enter the literal result element
<items>
and an
RDF sequence element,
rdf:Seq
. The sequence constructor
<xsl:for-each>
will take the processor to
all of the matching nodes one by one, changing the context node as it goes. You will learn more about
<xsl:for-each>
in Chapter 4.
By selecting with the XPath expression
feed//entry
(using
"//"
), you operate on all the entry elements
in the feed. For each entry, you add an RDF list item,
rdf:li
,andsetits
rdf:resource
attribute value
from the
<link>
element in each individual entry:
<items>
<rdf:Seq>
19