Skip to content

Instantly share code, notes, and snippets.

@Answeror
Last active August 29, 2015 14:03
Show Gist options
  • Save Answeror/f4b337c06bf746969244 to your computer and use it in GitHub Desktop.
Save Answeror/f4b337c06bf746969244 to your computer and use it in GitHub Desktop.
Bangumi评论订阅
<?xml version='1.0' encoding='UTF-8'?>
<xsl:stylesheet
version='1.0'
xmlns:xsl='http://www.w3.org/1999/XSL/Transform'
xmlns:re='http://exslt.org/regular-expressions'
extension-element-prefixes='re'
>
<xsl:output method='xml' encoding='UTF-8'/>
<xsl:template match='/'>
<feed xml:lang='zh-CN' xmlns='http://www.w3.org/2005/Atom'>
<id>{{ id }}</id>
<link rel='alternate' type='text/html' href='http://{{ id }}'/>
<title><xsl:value-of select='//title[1]'/></title>
<xsl:apply-templates select='//div[@id="comment_list"]' mode='comments'/>
</feed>
</xsl:template>
<xsl:template match='div' mode='comments'>
<xsl:for-each select='.//div[contains(@id, "post_")]'>
<xsl:variable name='date' select='.//div[@class="re_info"][1]/small/text()'/>
<xsl:variable name='year' select='re:replace($date, "^.* - (\d+)-(\d+)-(\d+) (\d+):(\d+)[\s\S]*$", "", "\1")'/>
<xsl:variable name='month' select='re:replace($date, "^.* - (\d+)-(\d+)-(\d+) (\d+):(\d+)[\s\S]*$", "", "\2")'/>
<xsl:variable name='day' select='re:replace($date, "^.* - (\d+)-(\d+)-(\d+) (\d+):(\d+)[\s\S]*$", "", "\3")'/>
<xsl:variable name='hour' select='re:replace($date, "^.* - (\d+)-(\d+)-(\d+) (\d+):(\d+)[\s\S]*$", "", "\4")'/>
<xsl:variable name='minute' select='re:replace($date, "^.* - (\d+)-(\d+)-(\d+) (\d+):(\d+)[\s\S]*$", "", "\5")'/>
<xsl:variable name='time' select='concat($year, "-", format-number($month, "00"), "-", format-number($day, "00"), "T", format-number($hour, "00"), ":", format-number($minute, "00"), ":00Z")'/>
<xsl:variable name='content' select='.//div[@class="message" or @class="cmt_sub_content"]'/>
<entry>
<id><xsl:value-of select='@id'/></id>
<published><xsl:value-of select='$time'/></published>
<updated><xsl:value-of select='$time'/></updated>
<link rel='alternate' type='text/html'>
<xsl:attribute name='href'>
<xsl:value-of select='.//div[@class="re_info"][1]//a[1]/@href'/>
</xsl:attribute>
</link>
<title><xsl:value-of select='normalize-space(.//div[@class="re_info"][1]//a[1])'/></title>
<summary><xsl:value-of select='$content[1]'/></summary>
<content type='html'>
<xsl:text disable-output-escaping="yes">&lt;![CDATA[</xsl:text>
<xsl:apply-templates select='$content[1]/node()' mode='content'/>
<xsl:text disable-output-escaping="yes">]]&gt;</xsl:text>
</content>
<author>
<name><xsl:value-of select='.//div[@class="inner"]//a[1]'/></name>
<url><xsl:value-of select='.//div[@class="inner"]//a[1]/@href'/></url>
</author>
</entry>
</xsl:for-each>
</xsl:template>
<xsl:template match='*' mode='content'>
<xsl:copy-of select="."/>
</xsl:template>
<xsl:template match='img' mode='content'>
<img alt='{@alt}' smileid='{@smileid}'>
<xsl:attribute name="src">
<xsl:if test="starts-with(@src, '/')">http://bgm.tv</xsl:if>
<xsl:value-of select="@src"/>
</xsl:attribute>
</img>
</xsl:template>
</xsl:stylesheet>
{
"@xslt": {
"html_encoded": {
"[body]":{"@request": "http://bgm.tv{{ path }}"}
},
"xslt": {
"@jinja2": {
"template": {"text<": "bgm_comments.xslt"},
"kargs": {"id": "bgm.tv{{ path }}"}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment