【发布时间】:2014-03-02 05:28:31
【问题描述】:
我是 XSLT 的新手,正在尝试将从 W3C 新闻提要中提取的 atom XML 文件转换为 HTML。 XML文件如下所示:
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<title>W3C News</title>
<link rel="alternate" type="text/html" href="http://www.w3.org/" />
<link rel="self" type="application/atom+xml" href="http://www.w3.org/News/atom.xml" />
<id>tag:www.w3.org,2008-09-29://4</id>
<updated>2013-09-06T16:31:45Z</updated>
<generator uri="http://www.sixapart.com/movabletype/">Movable Type 4.34-en</generator>
<entry>
<title>WebCrypto Key Discovery Working Draft Published</title>
<link rel="alternate" type="text/html" href="http://www.w3.org/News/2013.html#entry-9920" />
<id>tag:www.w3.org,2013://4.9920</id>
<published>2013-08-22T16:40:18Z</published>
<updated>2013-08-22T16:40:18Z</updated>
<summary>The Web Cryptography Working Group has published a Working Draft of WebCrypto Key Discovery. This specification describes a JavaScript API for discovering named, origin-specific pre-provisioned cryptographic keys for use with the Web Cryptography API. Pre-provisioned keys are keys which have...</summary>
<author>
<name>W3C Staff</name>
</author>
<category term="Publication" scheme="http://www.sixapart.com/ns/types#category" />
<category term="Web Design and Applications" scheme="http://www.sixapart.com/ns/types#category" />
<content type="html" xml:lang="en" xml:base="http://www.w3.org/">
<![CDATA[<p>The <a href="http://www.w3.org/2012/webcrypto/">Web Cryptography Working Group</a> has published a Working Draft of <a href="http://www.w3.org/TR/2013/WD-webcrypto-key-discovery-20130822/">WebCrypto Key Discovery</a>. This specification describes a JavaScript API for discovering named, origin-specific pre-provisioned cryptographic keys for use with the Web Cryptography API. Pre-provisioned keys are keys which have been made available to the user agent by means other than the generation, derivation, importation functions of the Web Cryptography API. Origin-specific keys are keys that are available only to a specified origin. Named keys are identified by a name assumed to be known to the origin in question and provisioned with the key itself. Learn more about the <a href="http://www.w3.org/Security/">Security Activity</a>.</p>]]>
</content>
</entry>
<entry>
<title>Three RDFa Recommendations Published</title>
<link rel="alternate" type="text/html" href="http://www.w3.org/News/2013.html#entry-9919" />
<id>tag:www.w3.org,2013://4.9919</id>
<published>2013-08-22T16:15:02Z</published>
<updated>2013-08-22T16:15:02Z</updated>
<summary> The RDFa Working Group today published three RDFa Recommendations. RDFa lets authors put machine-readable data in HTML documents. Using RDFa, authors may turn their existing human-visible text and links into machine-readable data without repeating content. Today's publications were: HTML+RDFa...</summary>
<author>
<name>W3C Staff</name>
</author>
<category term="Publication" scheme="http://www.sixapart.com/ns/types#category" />
<category term="Semantic Web" scheme="http://www.sixapart.com/ns/types#category" />
<content type="html" xml:lang="en" xml:base="http://www.w3.org/">
<![CDATA[<p>
<a href="/2001/sw/" class="imageLink">
<img src="http://www.w3.org/Icons/SW/sw-cube.png" alt="Semantic Web Cube"/>
</a>
The <a href="/2010/02/rdfa/">RDFa Working Group</a> today published three RDFa Recommendations. RDFa lets authors put machine-readable data in HTML documents. Using RDFa, authors may turn their existing human-visible text and links into machine-readable data without repeating content. Today's publications were:</p>
<ul class="show_items">
<li><a href="http://www.w3.org/TR/2013/REC-html-rdfa-20130822/">HTML+RDFa 1.1</a>,
which defines rules and guidelines for adapting the RDFa Core 1.1 and RDFa Lite 1.1 specifications for use in HTML5 and XHTML5. The rules defined in this specification not only apply to HTML5 documents in non-XML and XML mode, but also to HTML4 and XHTML documents interpreted through the HTML5 parsing rules.</li>
<li>The group also published two Second Editions for <a href="http://www.w3.org/TR/2013/REC-rdfa-core-20130822/">RDFa Core 1.1</a> and <a href="http://www.w3.org/TR/2013/REC-xhtml-rdfa-20130822/">XHTML+RDFa 1.1</a>, folding in the errata reported by the community since their publication as Recommendations in June 2012; all changes were editorial.</li>
<li>The group also updated the a <a href="/TR/2013/NOTE-rdfa-primer-20130822/">RDFa 1.1 Primer</a>.</li>
</ul>
<p>Learn more about the <a href="/2001/sw/">Semantic Web Activity</a>.</p>]]>
</content>
</entry>
</feed>
我现在想要的只是将每个entry 中的title 作为一个列表。我写的XSLT如下图:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:p="http://www.w3.org/2005/Atom"
xmlns="http://www.w3.org/1999/xhtml"
version="1.0">
<xsl:output method="xml"
omit-xml-declaration="yes"
doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"
doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"/>
<xsl:template match="feed">
<html>
<body>
<h1>W3C Atom Document</h1>
<ul>
<xsl:apply-templates/>
</ul>
</body>
</html>
</xsl:template>
<xsl:template match="entry">
<li>
<xsl:value-of select="title" />
</li>
</xsl:template>
</xsl:stylesheet>
运行 Xalan 后,生成的 HTML 似乎包含每个叶节点的所有值,而不是列出所有条目的标题。不确定我的代码有什么问题。谢谢。
【问题讨论】:
标签: xml xslt xslt-1.0 atom-feed xalan