<xsl:transform 
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
  xmlns:atom="http://purl.org/atom/ns#" 
  xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" 
  version="1.0" >

<xsl:template match="@id|@href|@type">
   <xsl:if test="../ancestor::*[@type='literal']">
     <xsl:copy>
       <xsl:apply-templates select="@*"/>
       <xsl:apply-templates/>
     </xsl:copy>
   </xsl:if>
</xsl:template>

<xsl:template match="node()|@*">
   <xsl:choose>
      <xsl:when test="../atom:atom">
        <!-- The atom documentElement, atom:atom -->
        <rdf:RDF>
          <xsl:apply-templates select="@*"/>
          <xsl:apply-templates/>
        </rdf:RDF>
      </xsl:when>

      <xsl:when test="../../atom:atom">
        <!-- Node element children of atom:atom -->
        <xsl:copy>
          <xsl:if test="@id">
            <xsl:attribute name="rdf:about">
              <xsl:value-of select="@id"/>
            </xsl:attribute>
          </xsl:if>
          <xsl:apply-templates select="@*"/>
          <xsl:apply-templates/>
        </xsl:copy>
      </xsl:when>

      <xsl:when test="ancestor::*[@type='literal']">
        <!-- Literal content (just copy it) -->
        <xsl:copy>
          <xsl:apply-templates select="@*"/>
          <xsl:apply-templates/>
        </xsl:copy>
      </xsl:when>

      <xsl:when test="../../../* and @id">
        <!-- Node element -->
        <xsl:copy>
          <rdf:Description>
            <xsl:attribute name="rdf:about">
              <xsl:value-of select="@id"/>
            </xsl:attribute>
            <xsl:apply-templates select="@*"/>
            <xsl:apply-templates/>
          </rdf:Description>
        </xsl:copy>
      </xsl:when>

      <xsl:when test="../../../* and not(@id)">
        <!-- Property element -->
        <xsl:copy>
          <xsl:if test="@type='literal'">
             <xsl:attribute name="rdf:parseType">Literal</xsl:attribute>
          </xsl:if>
          <xsl:if test="./* and not(@type='literal')">
             <xsl:attribute name="rdf:parseType">Resource</xsl:attribute>
          </xsl:if>
          <xsl:if test="@href and not(./*)">
            <xsl:attribute name="rdf:resource">
              <xsl:value-of select="@href"/>
            </xsl:attribute>
          </xsl:if>
          <xsl:apply-templates select="@*"/>
          <xsl:apply-templates/>
        </xsl:copy>
      </xsl:when>
   </xsl:choose>
</xsl:template>

</xsl:transform>