-
Notifications
You must be signed in to change notification settings - Fork 0
/
properties.xslt
103 lines (93 loc) · 3.77 KB
/
properties.xslt
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
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:pxrutils="xalan://com.brentcroft.pxr.PxrUtils"
xmlns:xalan="http://xml.apache.org/xalan">
<xsl:output
method="text"
encoding="ISO-8859-1"
xalan:line-separator="
"/>
<xsl:variable name="NL"><xsl:text> </xsl:text></xsl:variable>
<xsl:template match="text()"/>
<xsl:template match="/">
<xsl:for-each select="//comment[ @key='_header' ]">
<xsl:apply-templates select="."/>
</xsl:for-each>
<xsl:for-each select="//entry[ not( @key='_header' or @key='_footer' ) ]">
<xsl:sort select="@index" data-type="number"/>
<xsl:variable name="key" select="@key"/>
<xsl:for-each select="preceding-sibling::comment[ @key = $key ]">
<xsl:apply-templates select="."/>
</xsl:for-each>
<xsl:apply-templates select="."/>
</xsl:for-each>
<xsl:for-each select="//comment[ @key='_footer' ]">
<xsl:apply-templates select="."/>
</xsl:for-each>
</xsl:template>
<xsl:template match="comment">
<xsl:variable name="text" select="text()"/>
<xsl:call-template name="lines-before">
<xsl:with-param name="lines" select="number( @lines-before )"/>
</xsl:call-template>
<xsl:if test="string-length( normalize-space( $text ) ) > 1 and not( starts-with( $text, '#' ) )">
<xsl:text>#</xsl:text>
</xsl:if>
<xsl:value-of select="$text"/>
<xsl:if test="not( @eol = '0' )">
<xsl:value-of select="$NL"/>
</xsl:if>
</xsl:template>
<xsl:template match="entry">
<xsl:call-template name="lines-before">
<xsl:with-param name="lines" select="number( @lines-before )"/>
</xsl:call-template>
<xsl:value-of select="pxrutils:escapeKey( @key )"/>
<xsl:choose>
<xsl:when test="@sep">
<xsl:value-of select="@sep"/>
</xsl:when>
<xsl:otherwise>=</xsl:otherwise>
</xsl:choose>
<xsl:choose>
<xsl:when test="text">
<xsl:apply-templates select="text">
<xsl:sort select="@key" data-type="number"/>
</xsl:apply-templates>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="pxrutils:escapeValue( text() )"/>
</xsl:otherwise>
</xsl:choose>
<xsl:if test="not( @eol = '0' )">
<xsl:value-of select="$NL"/>
</xsl:if>
</xsl:template>
<xsl:template match="text">
<xsl:variable name="value" select="text()"/>
<xsl:choose>
<xsl:when test="( @key = '0' )"><xsl:value-of select="pxrutils:escapeValue( $value )"/></xsl:when>
<xsl:when test="( @eol = '0' ) and not( $value ) and not( @prefix )">
<xsl:text>\</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text>\</xsl:text>
<xsl:if test="not( @eol = '0' ) or $value or @prefix">
<xsl:value-of select="$NL"/>
</xsl:if>
<xsl:value-of select="@prefix"/>
<xsl:value-of select="pxrutils:escapeValue( $value )"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="lines-before">
<xsl:param name="lines" select="0"/>
<xsl:if test="$lines > 0">
<xsl:value-of select="$NL"/>
<xsl:call-template name="lines-before">
<xsl:with-param name="lines" select="$lines - 1"/>
</xsl:call-template>
</xsl:if>
</xsl:template>
</xsl:stylesheet>