本文介绍了用xslt解析html的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有人可以帮我看看以下内容:
下面是一个笨拙的方式来提取< span class =date> 元素的内容(或者更确切地说,< span class =date> 元素禁用转义之后):
< xsl:value-of select =substring-before(substring-after(description,'& lt; span class =& quot; date& quot;& gt;'),& lt; /跨度&安培; GT;')/>
Can someone help me take the following:
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0"> <channel> <title>This is a test</title> <link>http://somelink.html</link> <description>RSS Feed</description> <item> <title>This is a title</title> <link>http://somelink.html</link> <description><div style='font-size: 9px;'><div class="rendering rendering_researchoutput rendering_researchoutput_short rendering_contributiontojournal rendering_short rendering_contributiontojournal_short"><h2 class="title"><a class="link" rel="ContributionToJournal" href="http://somelink.html"><span>This is a Title</span></a></h2><a class="link person" rel="Person" href="somelink.html"><span>Bob, C. R</span></a> &amp; Smith, W. <span class="date">2014</span> <span class="journal">In : <a class="link" rel="Journal" href="http://somelink.html"><span>Publishers title</span></a>.</span><p class="type"><span class="type_family">Research output<span class="type_family_sep">: </span></span><span class="type_classification_parent">Contribution to journal<span class="type_parent_sep"> › </span></span><span class="type_classification">Article</span></p></div><div class="rendering rendering_researchoutput rendering_researchoutput_detailsportal rendering_contributiontojournal rendering_detailsportal rendering_contributiontojournal_detailsportal"><div class="article"><table class="properties"><tbody><tr class="language"><th>Original language</th><td>English</td></tr><tr><th>Journal</th><td><a class="link" rel="Journal" href="http://somelink.html"><span>Journal of Human Rights and the Environment </span></a></td></tr><tr><th>Journal publication date</th><td>2014</td></tr><tr class="status"><th>State</th><td>In press</td></tr></tbody></table></div></div></div></description> <pubDate>Wed, 02 Apr 2014 15:59:41 GMT</pubDate> <guid>http://somelink.html</guid> <dc:date>2014-04-02T15:59:41Z</dc:date> </item> </channel> </rss>And show me how to use XSLT to parse the <description> tag to return the contents of the <span class="..."> fields or <div class='...'> fields?
I tried the following in my xslt:
<xsl:value-of select="span[@class='date']"/>Which returns nothing
解决方案Here's a clumsy way to extract the contents of the <span class="date"> element (or rather what would be the <span class="date"> element after disabling the escaping):
<xsl:value-of select="substring-before(substring-after(description, '<span class="date">'), '</span>')"/>
这篇关于用xslt解析html的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!