这是XML:
<?xml version='1.0' encoding='UTF-8' standalone='yes' ?>
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
<title>Rated Images</title>
<link rel="self" href="http://mirror/blog/?feed=photos&lang=en" />
<link rel="alternate" type="text/html" href="http://mirror/blog"/>
<icon>http://mirror/avatars/sterling-adventures.jpg</icon>
<subtitle>Just another WordPress site</subtitle>
<updated>2012-03-20T09:50:48+00:00</updated>
<generator uri="http://mirror/">Test</generator>
<entry>
<title>Les Houches</title>
<link rel='alternate' type='text/html' href='http://mirror/blog/2011/12/28/les-houches/' />
<published>2011-12-28T11:29:29+00:00</published>
<id>http://mirror/blog/wp-content/uploads/2011/12/IMG_8830.jpg</id>
<updated>2011-12-28T11:29:29+00:00</updated>
<content type='html'>
<p><a href="http://mirror/blog/author/admin/">admin</a> posted a photo from Les Houches:</p>
<p><a href="http://mirror/blog/2011/12/28/les-houches/" title="Les Houches"><img src="http://mirror/blog/wp-content/uploads/2011/12/IMG_8830.jpg" width="138" height="160" alt="" /></a></p>
</content>
<author>
<name>admin</name>
<uri>http://mirror/blog/author/admin/</uri>
</author>
<link rel='enclosure' type='image/jpeg' href='http://mirror/blog/wp-content/uploads/2011/12/IMG_8830.jpg' />
</entry>
</feed>
我想要回来的只是link元素的href属性,其他一切都可以被丢弃。也就是说,out的每一行应该是一个链接href ...
希望有人可以帮我构建合适的XSLT ......
: - )
答案 0 :(得分:2)
也许这会有所帮助
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions" xmlns:atom="http://www.w3.org/2005/Atom">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="/">
<output>
<xsl:for-each select="/atom:feed/atom:entry/atom:link">
<xsl:value-of select="@href"/>
</xsl:for-each>
</output>
</xsl:template>
</xsl:stylesheet>