Link to maintainership/funding post
[grauphel.git] / templates / html2tomboy.xsl
1 <?xml version="1.0" encoding="utf-8"?>
2 <xsl:stylesheet version="1.0"
3   xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
4   xmlns:h="http://www.w3.org/1999/xhtml"
5 >
6  <!--
7   Convert HTML generated by grauphel's tomboy2html converter
8   back into the tomboy note markup
9  -->
10  <xsl:output omit-xml-declaration="yes"/>
11
12  <xsl:template match="/">
13   <xsl:apply-templates select="h:html/h:body"/>
14  </xsl:template>
15
16  <xsl:template match="h:body">
17   <xsl:call-template name="content"/>
18  </xsl:template>
19
20  <xsl:template name="content">
21   <xsl:for-each select="child::node()">
22    <xsl:choose>
23     <xsl:when test="local-name(.) = ''">
24      <xsl:call-template name="string-replace-all">
25       <xsl:with-param name="text" select="string(.)" />
26       <xsl:with-param name="replace" select="'&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;'" />
27       <xsl:with-param name="by" select="'&#09;'" />
28      </xsl:call-template>
29     </xsl:when>
30     <xsl:when test="local-name(.) = 'br'">
31      <!-- do nothing -->
32     </xsl:when>
33     <xsl:when test="local-name(.) = 'ul'">
34      <list>
35       <xsl:for-each select="h:li">
36        <list-item dir="ltr"><xsl:call-template name="content"/></list-item>
37       </xsl:for-each>
38      </list>
39     </xsl:when>
40     <xsl:when test="local-name(.) = 'b'">
41      <bold><xsl:call-template name="content"/></bold>
42     </xsl:when>
43     <xsl:when test="local-name(.) = 'i'">
44      <italic><xsl:call-template name="content"/></italic>
45     </xsl:when>
46     <xsl:when test="local-name(.) = 'span' and @class = 'strikethrough'">
47      <strikethrough><xsl:call-template name="content"/></strikethrough>
48     </xsl:when>
49     <xsl:when test="local-name(.) = 'span' and @class = 'highlight'">
50      <highlight><xsl:call-template name="content"/></highlight>
51     </xsl:when>
52     <xsl:when test="local-name(.) = 'span' and contains(@style, 'monospace')">
53      <monospace><xsl:call-template name="content"/></monospace>
54     </xsl:when>
55     <xsl:when test="local-name(.) = 'span' and @class = 'small'">
56      <xsl:text disable-output-escaping="yes">&lt;size:small></xsl:text>
57      <xsl:call-template name="content"/>
58      <xsl:text disable-output-escaping="yes">&lt;/size:small></xsl:text>
59     </xsl:when>
60     <xsl:when test="local-name(.) = 'span' and @class = 'large'">
61      <xsl:text disable-output-escaping="yes">&lt;size:large></xsl:text>
62      <xsl:call-template name="content"/>
63      <xsl:text disable-output-escaping="yes">&lt;/size:large></xsl:text>
64     </xsl:when>
65     <xsl:when test="local-name(.) = 'span' and @class = 'huge'">
66      <xsl:text disable-output-escaping="yes">&lt;size:huge></xsl:text>
67      <xsl:call-template name="content"/>
68      <xsl:text disable-output-escaping="yes">&lt;/size:huge></xsl:text>
69     </xsl:when>
70     <xsl:when test="local-name(.) = 'a' and contains(@href, '://')">
71      <xsl:text disable-output-escaping="yes">&lt;link:url></xsl:text>
72      <xsl:choose>
73       <xsl:when test="starts-with(@href, 'file://')">
74        <xsl:value-of select="substring(@href, 8)"/>
75       </xsl:when>
76       <xsl:otherwise>
77        <xsl:value-of select="@href"/>
78       </xsl:otherwise>
79      </xsl:choose>
80      <xsl:text disable-output-escaping="yes">&lt;/link:url></xsl:text>
81     </xsl:when>
82     <xsl:when test="local-name(.) = 'a' and not(contains(@href, '://'))">
83      <xsl:text disable-output-escaping="yes">&lt;link:internal></xsl:text>
84      <xsl:call-template name="content"/>
85      <xsl:text disable-output-escaping="yes">&lt;/link:internal></xsl:text>
86     </xsl:when>
87     <xsl:otherwise>
88      <xsl:message terminate="yes">
89       Unsupported tag
90       <xsl:value-of select="local-name(.)"/>
91      </xsl:message>
92     </xsl:otherwise>
93    </xsl:choose>
94   </xsl:for-each>
95  </xsl:template>
96
97  <!-- http://geekswithblogs.net/Erik/archive/2008/04/01/120915.aspx -->
98  <xsl:template name="string-replace-all">
99   <xsl:param name="text" />
100   <xsl:param name="replace" />
101   <xsl:param name="by" />
102   <xsl:choose>
103    <xsl:when test="contains($text, $replace)">
104     <xsl:value-of select="substring-before($text,$replace)" />
105     <xsl:value-of select="$by" />
106     <xsl:call-template name="string-replace-all">
107      <xsl:with-param name="text" select="substring-after($text,$replace)" />
108      <xsl:with-param name="replace" select="$replace" />
109      <xsl:with-param name="by" select="$by" />
110     </xsl:call-template>
111    </xsl:when>
112    <xsl:otherwise>
113     <xsl:value-of select="$text" />
114    </xsl:otherwise>
115   </xsl:choose>
116  </xsl:template>
117 </xsl:stylesheet>