Project

General

Profile

1
<?xml version="1.0" encoding="UTF-8"?>
2
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
3
    xmlns:xs="http://www.w3.org/2001/XMLSchema" exclude-result-prefixes="xs" version="2.0">
4
    <xd:doc xmlns:xd="http://www.oxygenxml.com/ns/doc/xsl" scope="stylesheet">
5
        <xd:desc>
6
            <xd:p><xd:b>Created on:</xd:b> Dec 5, 2011</xd:p>
7
            <xd:p><xd:b>Author:</xd:b> rviglianti</xd:p>
8
            <xd:p><xd:b>Author:</xd:b> flawrence</xd:p>
9
            <xd:p></xd:p>
10
        </xd:desc>
11
    </xd:doc>
12
                
13
    <xsl:template name="sqbrackets">
14
        <!--<xsl:variable name="startspace" select="if (matches(substring(.,1,1),'[\n\r\s\t]')) then ' ' else ''"/>
15
        <xsl:variable name="endspace" select="if (matches(substring(.,string-length(.)),'[\n\r\s\t]')) then ' ' else ''"/>-->
16
        <xsl:variable name="current" select="replace(., '([^\]])\]([ \t]*)\[([^\[])', '$1$2$3')" />
17
        <xsl:variable name="strlength" select="string-length($current)"/>
18
        <xsl:variable name="firstletter" select="substring($current, 1, 1)"/>
19
        <xsl:variable name="lastletter" select="substring($current, $strlength)"/>
20
        
21
        <!--<xsl:value-of select="$startspace"/>-->
22
        
23
        <xsl:choose>
24
            <xsl:when test="$firstletter = '[' or $lastletter = ']'">
25
                
26
                <xsl:variable name="previous" select="preceding::text()[1]" />
27
                <xsl:variable name="after" select="following::text()[1]" />
28
                
29
                <!-- get the first text node before the next br (if this node matches current text node then there is a br between this text node and the next text node so don't strip brackets) -->
30
                <xsl:variable name="beforenextbr" select="following::br[1]/preceding::text()[1]"/>
31
                
32
                <!-- get the first next node following the preceding br (if this node matches current text node then there is a br between this text node and the previous text node so don't strip brackets)-->
33
                <xsl:variable name="afterprevbr" select="preceding::br[1]/following::text()[1]"/>
34
                <xsl:variable name="afirstletter" select="substring(normalize-space($after), 1, 1)"/>
35
                <xsl:variable name="plastletter" select="substring(normalize-space($previous), string-length(normalize-space($previous)))"/>
36
                                
37
                <xsl:choose>
38
                    <xsl:when test="$plastletter = ']' and $afirstletter = '[' and $afterprevbr != . and $beforenextbr != .">
39
                        <xsl:value-of select="substring($current, 2, string-length($current)-2)"/>                                                
40
                    </xsl:when>
41
                    <xsl:when test="$plastletter = ']' and $afterprevbr != .">
42
                        <xsl:value-of select="substring($current, 2)"/>
43
                    </xsl:when>
44
                    <xsl:when test="$afirstletter = '[' and $beforenextbr != .">
45
                        <xsl:value-of select="substring($current, 1, string-length($current)-1)"/>
46
                    </xsl:when>
47
                    <xsl:otherwise>
48
                        <xsl:value-of select="$current"/>
49
                    </xsl:otherwise>
50
                </xsl:choose>
51
                
52
            </xsl:when>
53
            <xsl:otherwise>
54
                <xsl:value-of select="$current"/>
55
            </xsl:otherwise>
56
        </xsl:choose>
57
        <!--<xsl:value-of select="$endspace"/>-->
58
        
59
    </xsl:template>
60
    
61
</xsl:stylesheet>
(95-95/95)