microformat_transformer.xsl 1.77 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"
  xpath-default-namespace="http://www.w3.org/1999/xhtml"
  xmlns="http://www.w3.org/1999/xhtml">

  <xsl:output method="xml" indent="yes"/>

  <xsl:template match="node()|@*">
    <xsl:copy>
      <xsl:apply-templates select="node()|@*"/>
    </xsl:copy>
  </xsl:template>

  <!-- Traitement des micro-formats -->
  <xsl:template match="node()[local-name()=('h2', 'h3', 'h4', 'h5', 'h6') and parent::div[@data-hdoc-type=('definition', 'example', 'remark', 'advice', 'warning', 'complement', 'emphasis')]]">

    <xsl:variable name="prename" select="concat(lower-case(substring(./text(), 1, 1)), substring(./text(), 2))"/>
    <xsl:variable name="type" select="parent::div/@data-hdoc-type"/>
    <xsl:variable name="prefix">
      <xsl:choose>
        <xsl:when test="$type = 'definition'">
          <xsl:text>Définition</xsl:text>
        </xsl:when>
        <xsl:when test="$type = 'example'">
          <xsl:text>Exemple</xsl:text>
        </xsl:when>
        <xsl:when test="$type = 'remark'">
          <xsl:text>Remarque</xsl:text>
        </xsl:when>
        <xsl:when test="$type = 'advice'">
          <xsl:text>Conseil</xsl:text>
        </xsl:when>
        <xsl:when test="$type = 'warning'">
          <xsl:text>Attention</xsl:text>
        </xsl:when>
        <xsl:when test="$type = 'complement'">
          <xsl:text>Complément</xsl:text>
        </xsl:when>
        <xsl:when test="$type = 'emphasis'">
          <xsl:text>Fondamental</xsl:text>
        </xsl:when>
      </xsl:choose>
    </xsl:variable>

    <xsl:copy>
      <xsl:copy-of select="@*"/>
      <xsl:value-of select="concat($prefix, ' : ', $prename)"/>
    </xsl:copy>

  </xsl:template>

</xsl:stylesheet>