我正在尝试从以下 XML 代码的描述中获取注释数量:
<item>
<title>War Stats</title>
<link>http://www.reddit.com/r/politics/comments/r3p6r/war_stats/</link>
<guid isPermaLink="true">http://www.reddit.com/r/politics/comments/r3p6r/war_stats/</guid>
<pubDate>Mon, 19 Mar 2012 10:30:01 -0700</pubDate>
<description>submitted by <a href="http://www.reddit.com/user/focusing"> focusing </a> to <a href="http://www.reddit.com/r/politics/"> politics</a> <br/> <a href="http://i.imgur.com/8HpWg.jpg">[link]</a> <a href="http://www.reddit.com/r/politics/comments/r3p6r/war_stats/">[634 comments]</a></description>
</item>
如您所见,我想从中获取数字 634 并将其放入新 xml 文件的“分数”属性中
<xsl:attribute name="score">
<xsl:analyze-string select='description' regex='\d'>
<xsl:matching-substring>
<number><xsl:value-of select='.' /></number>
</xsl:matching-substring>
</xsl:analyze-string>
</xsl:attribute>
但我认为我做错了..
这是整个代码:
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:a="http://www.w3.org/2005/Atom"
xmlns:media='http://search.yahoo.com/mrss/'>
<xsl:template match="/">
<xsl:for-each select="/rss/channel/item">
<item>
<xsl:attribute name="type">reddit</xsl:attribute>
<xsl:variable name="redditTitle" content="title" />
<xsl:attribute name="name">
<xsl:if test="string-length(title) > 50">
<xsl:value-of select="concat(substring(title, 1, 75), '...')" />
</xsl:if>
<xsl:if test="string-length(title) < 50">
<xsl:value-of select="title" />
</xsl:if>
</xsl:attribute>
<xsl:attribute name="url">
<xsl:value-of select="link" />
</xsl:attribute>
<xsl:attribute name="image">http://dl.dropbox.com/u/8226356/Unief/DatabasesWebtechnologie/Praktijk/Project/Reddit_logo.thumbnail.png</xsl:attribute>
<xsl:attribute name="score">
<xsl:analyze-string select='description' regex='[0-9]+'>
<xsl:matching-substring>
<xsl:value-of select='.' />
</xsl:matching-substring>
</xsl:analyze-string>
</xsl:attribute>
</item>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
有人可以解释一下我该怎么做吗?