Datasheet
Williams c01.tex V3 - 07/31/2009 2:53pm Page 20
Chapter 1: First Steps with XSLT
<xsl:for-each select
=
"feed//entry">
<rdf:li>
<xsl:attribute name
=
"rdf:resource">
<xsl:value-of select
=
"link/@href"/>
</xsl:attribute>
</rdf:li>
</xsl:for-each>
</rdf:Seq>
</items>
Entry Elements
Still in the main template, you need to loop through the entries again to create a series of complete
<item>
elements in the output:
<xsl:for-each select
=
"//entry">
<xsl:apply-templates select
=
"."/>
</xsl:for-each>
In a template matching
<entry>
elements, you can handle the translation from Atom to Dublin
Core. Most of the translations are straightforward. Dublin Core doesn’t have an equivalent of the
<atom:updated>
element, so you use that value in
<dc:date>
. The language can be obtained from the
<content>
element’s
xml:lang
attribute. Another point to note is that there can be multiple categories
in entries, just as there can be multiple
<dc:subject>
elements. Therefore, you need to select the
label
attribute on the
<category>
element inside another
<xsl:for-each>
loop that creates the subject
elements.
In neither of these two schemas does the order of elements matter, or the number of occurrences, so you
can simply let the source sequence drive the process:
<xsl:template match
=
"entry">
<item>
<xsl:attribute name
=
"rdf:about">
<xsl:value-of select
=
"id"/>
</xsl:attribute>
<link>
<xsl:value-of select
=
"link/@href"/>
</link>
<dc:identifier>
<xsl:value-of select
=
"id"/>
</dc: identifier >
<dc:language>
<xsl:value-of select
=
"content/@xml:lang"/>
</dc:language>
<dc:title>
<xsl:value-of select
=
"title"/>
</dc:title>
<dc:date>
<xsl:value-of select
=
"published"/>
</dc:date>
<dc:creator>
<xsl:value-of select
=
"author/name"/>
</dc:creator>
20