atom:contentのmode属性

どうやらmt-atom.cgiでエントリーの本文を拾う場合、必ずしも

<content xmlns="http://purl.org/atom/ns#" mode="xml" type="application/xhtml+xml">
  <div xmlns="http://www.w3.org/1999/xhtml">本文</div>
</content>

という形式になるとは限らないみたいだ。こういう場合もある。

<content xmlns="http://purl.org/atom/ns#" mode="escaped" type="application/xhtml+xml">本文(&lt;_&gt;)</content>

本文にHTMLエンティティが含まれる場合にはこうなるみたい。でもHTMLエンティティが含まれていても、HTMLタグも使っている場合は<content mode="xml">となって<div>で囲まれるみたい。ってことでXSLTを修正した。

<?xml version="1.0" encoding="utf-8" ?>
<xsl:stylesheet version="1.0"
  xmlns:atom="http://purl.org/atom/ns#"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:xhtml="http://www.w3.org/1999/xhtml"
  xmlns:dc="http://purl.org/dc/elements/1.1/">
<xsl:output method='html' version='1.0' encoding='UTF-8' indent='no'/>

<xsl:template match="atom:entry">
  <textarea>
    <xsl:if test="not(atom:content/@mode='escaped')">
      <xsl:copy-of select="atom:content/xhtml:div/node()"/>
    </xsl:if>
    <xsl:if test="atom:content/@mode='escaped'">
      <xsl:value-of select="atom:content"/>
    </xsl:if>
  </textarea>
</xsl:template>

</xsl:stylesheet>