comparison doc/wiki2docbook/html2db/html2db-utils.xsl @ 1734:b92fc3c922ac

scripts for converting wiki documentation to docbook
author nadvornik
date Sun, 22 Nov 2009 09:12:22 +0000
parents
children
comparison
equal deleted inserted replaced
1733:91a65afb5d77 1734:b92fc3c922ac
1 <?xml version="1.0" encoding="utf-8"?>
2 <!-- Copyright 2004 by Laszlo Systems, Inc.
3 Released under the Artistic License.
4 Written by Oliver Steele.
5 http://osteele.com/sources/xslt/htm2db/
6
7 Utility functions
8 -->
9 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
10 xmlns:exslt="http://exslt.org/common"
11 xmlns:math="http://exslt.org/math"
12 xmlns:xalan="http://xml.apache.org/xalan"
13 xmlns:html2db="urn:html2db"
14 xmlns:db="urn:docbook"
15 xmlns:h="http://www.w3.org/1999/xhtml"
16 exclude-result-prefixes="db exslt h html2db math xalan"
17 extension-element-prefixes="html2db"
18 version="1.0">
19
20 <!-- Wrap with ", and backslash " and \ -->
21 <xsl:template name="quote">
22 <xsl:param name="str" select="string(.)"/>
23 <xsl:param name="lquo" select="'&quot;'"/>
24 <xsl:param name="rquo" select="'&quot;'"/>
25 <!-- first " -->
26 <xsl:variable name="qpos" select="string-length(substring-before($str, '&quot;'))"/>
27 <!-- first \ -->
28 <xsl:variable name="bspos" select="string-length(substring-before($str, '\\'))"/>
29 <!-- first " or \ -->
30 <xsl:variable name="pos">
31 <xsl:choose>
32 <xsl:when test="$qpos=0"><xsl:value-of select="$bspos"/></xsl:when>
33 <xsl:when test="$bspos=0"><xsl:value-of select="$qpos"/></xsl:when>
34 <xsl:when test="$qpos&lt;$bspos">
35 <xsl:value-of select="$qpos"/>
36 </xsl:when>
37 <xsl:when test="$bspos">
38 <xsl:value-of select="$bspos"/>
39 </xsl:when>
40 </xsl:choose>
41 </xsl:variable>
42 <xsl:value-of select="$lquo"/>
43 <xsl:choose>
44 <xsl:when test="$pos!=0">
45 <xsl:value-of select="substring($str, 1, $pos)"/>
46 <xsl:text>\</xsl:text>
47 <xsl:value-of select="substring($str, $pos + 1, 1)"/>
48 <xsl:call-template name="quote">
49 <xsl:with-param name="str" select="substring($str, $pos + 2)"/>
50 <xsl:with-param name="lquo" select="''"/>
51 <xsl:with-param name="rquo" select="''"/>
52 </xsl:call-template>
53 </xsl:when>
54 <xsl:otherwise>
55 <xsl:value-of select="$str"/>
56 </xsl:otherwise>
57 </xsl:choose>
58 <xsl:value-of select="$rquo"/>
59 </xsl:template>
60
61 </xsl:stylesheet>