summaryrefslogtreecommitdiffstats
path: root/kate/tests/highlight.xsl
blob: d5699f31b67a542196c5e78cd24d5f72fdc6a286 (plain)
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<?xml version="1.0" encoding="iso-8859-15"?>

<!--
	This file is freely distributable, created by Wilbert Berendsen (wbsoft@xs4all.nl)

	This is just a simple XSLT file that converts some HTML pages to a XBEL bookmartdelist.
	It is included here to test the new XSLT highlighting by Peter Lammich.
	
	TODO: add better test file.
-->

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
xmlns:h="http://www.w3.org/1999/xhtml">
<xsl:output method="xml" encoding="iso-8859-15" indent="yes"
 doctype-public="+//IDN python.org//DTD XML Bookmark Exchange Language 1.0//EN//XML"
 doctype-system="http://www.python.org/topics/xml/dtds/xbel-1.0.dtd"
/>

<!-- main -->
<xsl:template match="/">
<xbel><folder><title>Linux at Home Links</title>
<xsl:for-each select="//*[@id='maincontents']//h:li">
  <xsl:variable name="f" select="document(h:a/@href)/h:html"/>
  <folder>
  <title><xsl:value-of select="h:a/h:strong"/></title>
  <desc><xsl:value-of select="normalize-space(h:a/text())"/></desc>
  <xsl:for-each select="$f//h:div[@id='maincontents']">
  <xsl:call-template name="getbookmarks"/>
  </xsl:for-each>
  
  </folder>
</xsl:for-each>
</folder></xbel>
</xsl:template>
<!-- end of main -->

<!-- get bookmarks from a page -->
<xsl:template name="getbookmarks">

<xsl:choose>
  <!-- harvest links from p or li elements -->
  <xsl:when test="self::h:li or self::h:p">
    <xsl:variable name="t" select="normalize-space()"/>
    <xsl:for-each select=".//h:a[1]">
      <xsl:call-template name="bookmark">
        <xsl:with-param name="desc" select="$t"/>
      </xsl:call-template>
    </xsl:for-each>
    <xsl:for-each select=".//h:a[position()!=1]">
      <xsl:call-template name="bookmark"/>
    </xsl:for-each>
  </xsl:when>


  <xsl:otherwise>
    <xsl:for-each select="*">
      <xsl:call-template name="getbookmarks"/>
    </xsl:for-each>
  </xsl:otherwise>

</xsl:choose>

</xsl:template>


<xsl:template name="bookmark">
  <xsl:param name="href" select="@href"/>
  <xsl:param name="desc" select="''"/>
  <xsl:param name="title" select="normalize-space()"/>

  <xsl:variable name="realdesc">
    <xsl:choose>
      <xsl:when test="starts-with($desc,$title)">
        <xsl:choose>
          <xsl:when test="starts-with(translate(substring-after($desc,$title),',.;','...'),'.')">
            <xsl:value-of select="substring($desc,string-length($title) + 2)"/>
          </xsl:when>
          <xsl:otherwise>
            <xsl:value-of select="substring-after($desc,$title)"/>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="$desc"/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:variable>
  
  <bookmark>
    <xsl:attribute name="href">
      <xsl:choose>
        <xsl:when test="starts-with($href,'http://') or starts-with($href,'ftp://') or starts-with($href,'mailto:')">
          <xsl:value-of select="$href"/>
        </xsl:when>
        <xsl:otherwise>
          <xsl:value-of select="concat('http://www.xs4all.nl/~wbsoft/linux/links/',$href)"/>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:attribute>
    <title><xsl:value-of select="normalize-space($title)"/></title>
    <xsl:if test="normalize-space($realdesc) != ''">
      <desc><xsl:value-of select="normalize-space($realdesc)"/></desc>
    </xsl:if>
  </bookmark>
</xsl:template>



</xsl:stylesheet>