-
Notifications
You must be signed in to change notification settings - Fork 4
/
lexis-nexis.xsl
executable file
·132 lines (98 loc) · 3.78 KB
/
lexis-nexis.xsl
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:orig="http://StatRev.xsd"
xmlns:fn="http://localhost/" xmlns:xs="http://www.w3.org/2001/XMLSchema" >
<!-- Strip whitespace from everything except the text of laws. -->
<xsl:strip-space elements="*" />
<xsl:preserve-space elements="bodyText" />
<!-- Don't include any whitespace-only text nodes. -->
<xsl:strip-space elements="*" />
<xsl:output
method="xml"
version="1.0"
encoding="utf-8"
omit-xml-declaration="no"
indent="yes"
media-type="text/xml"/>
<!--Start processing at the top-level element.-->
<xsl:template match="legislativeDoc">
<law>
<structure>
<xsl:for-each select="metadata/hierarchy">
<xsl:apply-templates select="hierarchyLevel"/>
</xsl:for-each>
</structure>
<!--Strip out the leading "_ " and replace any others with a colon.-->
<xsl:variable name="section-number" select="translate(legislativeDocBody/statute/level/anchor/@id, '_', ':')" />
<section_number>
<xsl:value-of select="substring($section-number, 2)"/>
</section_number>
<!--Include the catch line.-->
<catch_line><xsl:value-of select="legislativeDocBody/statute/level/heading/title" /></catch_line>
<history><xsl:value-of select="normalize-space(legislativeDocBody/statute/level/history/historyGroup/historyItem/bodyText)" /></history>
<text>
<xsl:for-each select="legislativeDocBody/statute">
<xsl:apply-templates select="level"/>
</xsl:for-each>
</text>
</law>
</xsl:template>
<!-- Recurse through structural hierarchies. -->
<xsl:template match="hierarchyLevel">
<unit>
<xsl:attribute name="label">
<xsl:value-of select="@levelType"/>
</xsl:attribute>
<xsl:attribute name="identifier">
<xsl:value-of select="replace(replace(normalize-space(heading/desig), '^(TITLE|SUBTITLE|ARTICLE|CHAPTER|SUBCHAPTER|PART) ', '' ), '.$', '')"/>
</xsl:attribute>
<!-- Counter -->
<xsl:attribute name="level">
<xsl:value-of select="count(ancestor::hierarchyLevel) + 1"/>
</xsl:attribute>
<xsl:value-of select="fn:capitalize_phrase(heading/title)"/>
</unit>
<xsl:if test="hierarchyLevel">
<xsl:apply-templates select="hierarchyLevel"/>
</xsl:if>
</xsl:template>
<!--Recurse through textual hierarchies (e.g., § 1(a)(iv)).-->
<xsl:template match="level">
<!-- Counter -->
<xsl:variable name="depth" select="count(ancestor::level)"/>
<!-- Handle -->
<xsl:choose>
<!-- Only include a prefix if we're at least 1 level deep. -->
<xsl:when test="$depth > 0">
<section>
<xsl:attribute name="prefix">
<xsl:variable name="prefix_length" select="string-length(heading/desig)"/>
<xsl:value-of select="substring(heading/desig, 0, $prefix_length)"/>
</xsl:attribute>
<xsl:value-of select="bodyText" />
<xsl:if test="level">
<xsl:apply-templates select="level"/>
</xsl:if>
</section>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="bodyText" />
<xsl:if test="level">
<xsl:apply-templates select="level"/>
</xsl:if>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:function name="fn:capitalize_word">
<xsl:param name="word" as="xs:string" />
<xsl:value-of select="concat( upper-case(substring( $word, 1, 1 )), lower-case(substring($word,2)) )" />
</xsl:function>
<xsl:function name="fn:capitalize_phrase">
<xsl:param name="phrase" as="xs:string" />
<xsl:variable name="tokens">
<xsl:for-each select="tokenize( normalize-space($phrase), ' ' )">
<xsl:value-of select="concat(fn:capitalize_word(.), ' ')"/>
</xsl:for-each>
</xsl:variable>
<xsl:value-of select="substring(string($tokens),1,string-length(string($tokens))-1)"/>
</xsl:function>
</xsl:stylesheet>