XSL file to convert HTML to tomboy markup
[grauphel.git] / templates / html2tomboy.xsl
diff --git a/templates/html2tomboy.xsl b/templates/html2tomboy.xsl
new file mode 100644 (file)
index 0000000..a354000
--- /dev/null
@@ -0,0 +1,93 @@
+<?xml version="1.0" encoding="utf-8"?>
+<xsl:stylesheet version="1.0"
+  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+  xmlns:h="http://www.w3.org/1999/xhtml"
+>
+ <!--
+  Convert HTML generated by grauphel's tomboy2html converter
+  back into the tomboy note markup
+ -->
+ <xsl:output omit-xml-declaration="yes"/>
+
+ <xsl:template match="/">
+  <xsl:apply-templates select="h:html/h:body"/>
+ </xsl:template>
+
+ <xsl:template match="h:body">
+  <xsl:call-template name="content"/>
+ </xsl:template>
+
+ <xsl:template name="content">
+  <xsl:for-each select="child::node()">
+   <xsl:choose>
+    <xsl:when test="local-name(.) = ''">
+     <xsl:value-of select="."/>
+    </xsl:when>
+    <xsl:when test="local-name(.) = 'br'">
+     <!-- do nothing -->
+    </xsl:when>
+    <xsl:when test="local-name(.) = 'ul'">
+     <list>
+      <xsl:for-each select="h:li">
+       <list-item dir="ltr"><xsl:call-template name="content"/></list-item>
+      </xsl:for-each>
+     </list>
+    </xsl:when>
+    <xsl:when test="local-name(.) = 'b'">
+     <bold><xsl:call-template name="content"/></bold>
+    </xsl:when>
+    <xsl:when test="local-name(.) = 'i'">
+     <italic><xsl:call-template name="content"/></italic>
+    </xsl:when>
+    <xsl:when test="local-name(.) = 'span' and @class = 'strikethrough'">
+     <strikethrough><xsl:call-template name="content"/></strikethrough>
+    </xsl:when>
+    <xsl:when test="local-name(.) = 'span' and @class = 'highlight'">
+     <highlight><xsl:call-template name="content"/></highlight>
+    </xsl:when>
+    <xsl:when test="local-name(.) = 'span' and contains(@style, 'monospace')">
+     <monospace><xsl:call-template name="content"/></monospace>
+    </xsl:when>
+    <xsl:when test="local-name(.) = 'span' and @class = 'small'">
+     <xsl:text disable-output-escaping="yes">&lt;size:small></xsl:text>
+     <xsl:call-template name="content"/>
+     <xsl:text disable-output-escaping="yes">&lt;/size:small></xsl:text>
+    </xsl:when>
+    <xsl:when test="local-name(.) = 'span' and @class = 'large'">
+     <xsl:text disable-output-escaping="yes">&lt;size:large></xsl:text>
+     <xsl:call-template name="content"/>
+     <xsl:text disable-output-escaping="yes">&lt;/size:large></xsl:text>
+    </xsl:when>
+    <xsl:when test="local-name(.) = 'span' and @class = 'huge'">
+     <xsl:text disable-output-escaping="yes">&lt;size:huge></xsl:text>
+     <xsl:call-template name="content"/>
+     <xsl:text disable-output-escaping="yes">&lt;/size:huge></xsl:text>
+    </xsl:when>
+    <xsl:when test="local-name(.) = 'a' and contains(@href, '://')">
+     <xsl:text disable-output-escaping="yes">&lt;link:url></xsl:text>
+     <xsl:choose>
+      <xsl:when test="starts-with(@href, 'file://')">
+       <xsl:value-of select="substring(@href, 8)"/>
+      </xsl:when>
+      <xsl:otherwise>
+       <xsl:value-of select="@href"/>
+      </xsl:otherwise>
+     </xsl:choose>
+     <xsl:text disable-output-escaping="yes">&lt;/link:url></xsl:text>
+    </xsl:when>
+    <xsl:when test="local-name(.) = 'a' and not(contains(@href, '://'))">
+     <xsl:text disable-output-escaping="yes">&lt;link:internal></xsl:text>
+     <xsl:call-template name="content"/>
+     <xsl:text disable-output-escaping="yes">&lt;/link:internal></xsl:text>
+    </xsl:when>
+    <xsl:otherwise>
+     <xsl:message terminate="yes">
+      Unsupported tag
+      <xsl:value-of select="local-name(.)"/>
+     </xsl:message>
+    </xsl:otherwise>
+   </xsl:choose>
+  </xsl:for-each>
+ </xsl:template>
+
+</xsl:stylesheet>