View File | Revision Log | Show Annotations | Download File | View Changeset
/hippo/hippo-documentation/hst_docs/trunk/scripts/doc2jcr.xsl
Revision: 21317
Committed: Thu Jan 14 17:03:06 2010 UTC (10 years, 5 months ago) by rbijlsma
Content type: application/xml
File size: 7720 byte(s)
Log Message:
HSTTWODOCS-242

File Contents

# Content
1 <?xml version="1.0" encoding="UTF-8"?>
2 <!--
3 NAME
4 :: Transform a file that is in a readable form of the Hippo XML format to the real Hippo XML format.
5
6 DATA
7 Author: R.Bijlsma
8 -->
9
10 <!-- choose version 1.0, 1.1? or 2.0 -->
11 <xsl:transform version='1.0'
12 xmlns:xsl='http://www.w3.org/1999/XSL/Transform'
13 xmlns:xs="http://www.w3.org/2001/XMLSchema"
14 xmlns:s='http://www.scholarita.org/structure'
15 xmlns:sv="http://www.jcp.org/jcr/sv/1.0"
16 xmlns:docs="http://www.hippoecm.org/nt/docs/1.2"
17 xmlns:jcr="http://www.jcp.org/jcr/1.0"
18 xmlns:hippostd="http://www.onehippo.org/jcr/hippostd/nt/2.0"
19 xmlns:hippo="http://www.onehippo.org/jcr/hippo/nt/2.0"
20 xmlns:h='http://www.w3.org/1999/xhtml'
21 >
22
23 <xsl:output
24 method="xml"
25 encoding="UTF-8"
26 indent="yes"
27 />
28
29 <!-- ___________________________________________________________________________________________________ -->
30 <xsl:template match="/s:list">
31 <xsl:apply-templates/>
32 </xsl:template>
33
34 <!-- ___________________________________________________________________________________________________ -->
35 <xsl:template match="text()" mode='value'>
36 <xsl:call-template name='escape'/>
37 </xsl:template>
38
39 <!-- ___________________________________________________________________________________________________-->
40 <xsl:template name="escape">
41 <xsl:param name='string' select='.'/>
42
43 <xsl:choose>
44 <xsl:when test='contains($string, "&lt;")'>
45 <xsl:call-template name='escape'>
46 <xsl:with-param name='string' select='substring-before($string, "&lt;")'/>
47 </xsl:call-template>
48 <xsl:text>&amp;lt;</xsl:text>
49 <xsl:call-template name='escape'>
50 <xsl:with-param name='string' select='substring-after($string, "&lt;")'/>
51 </xsl:call-template>
52 </xsl:when>
53 <xsl:when test='contains($string, "&gt;")'>
54 <xsl:value-of select='substring-before($string, "&gt;")'/>
55 <xsl:text>&amp;gt;</xsl:text>
56 <xsl:call-template name='escape'>
57 <xsl:with-param name='string' select='substring-after($string, "&gt;")'/>
58 </xsl:call-template>
59 </xsl:when>
60 <xsl:otherwise>
61 <xsl:value-of select='$string'/>
62 </xsl:otherwise>
63 </xsl:choose>
64 </xsl:template>
65
66 <!-- ___________________________________________________________________________________________________ -->
67 <xsl:template match='s:list[@elem="property"]'>
68 <xsl:for-each select='*'>
69 <xsl:text>&#10; </xsl:text>
70 <sv:property>
71 <xsl:attribute name='sv:name'><xsl:value-of select='name()'/></xsl:attribute>
72 <xsl:if test='not(@sv:type)'>
73 <xsl:attribute name='sv:type'>
74 <xsl:choose>
75 <xsl:when test='name()="jcr:primaryType" or name()="jcr:mixinTypes"'>Name</xsl:when>
76 <xsl:otherwise>String</xsl:otherwise>
77 </xsl:choose>
78 </xsl:attribute>
79 </xsl:if>
80 <xsl:choose>
81 <xsl:when test='sv:value'>
82 <xsl:for-each select='sv:value'>
83 <xsl:copy>
84 <xsl:apply-templates mode='value'/>
85 </xsl:copy>
86 </xsl:for-each>
87 </xsl:when>
88 <xsl:otherwise>
89 <xsl:choose>
90 <!-- Count
91 0 or 1
92 one 1
93 any 0 or more
94 some 1 or more
95 multi 2 or more
96
97 TODO The count attribute is not yet generated by jcr2doc.xsl (to be renamed cms2....xsl)
98 -->
99 <xsl:when test='.="@empty@" or not(@count="any" or @count="some" or @count="multi")'><sv:value/></xsl:when>
100 <xsl:when test='.=""'></xsl:when>
101 <xsl:otherwise>
102 <sv:value>
103 <xsl:apply-templates mode='value'/>
104 </sv:value>
105 </xsl:otherwise>
106 </xsl:choose>
107 </xsl:otherwise>
108 </xsl:choose>
109 <xsl:text>&#10; </xsl:text>
110 </sv:property>
111 </xsl:for-each>
112 </xsl:template>
113
114
115 <!-- ___________________________________________________________________________________________________ -->
116 <xsl:template name='values'>
117 <xsl:param name='string' select='.'/>
118
119 <xsl:variable name='sep'>
120 <xsl:choose>
121 <xsl:when test='contains($string, ":; ")'>:; </xsl:when>
122 <xsl:when test='contains($string, "; ")'>; </xsl:when>
123 <xsl:otherwise></xsl:otherwise>
124 </xsl:choose>
125 </xsl:variable>
126
127 <xsl:choose>
128 <xsl:when test='$sep=""'>
129 <xsl:if test='not($string="")'>
130 <xsl:text>&#10; </xsl:text>
131 <sv:value><xsl:if test='$string!="@empty@"'><xsl:value-of select='$string'></xsl:value-of></xsl:if></sv:value>
132 </xsl:if>
133 </xsl:when>
134 <xsl:otherwise>
135 <xsl:text>&#10; </xsl:text>
136 <sv:value><xsl:value-of select='substring-before($string, $sep)'></xsl:value-of></sv:value>
137 <xsl:call-template name='values'>
138 <xsl:with-param name='string' select='substring-after($string, $sep)'/>
139 </xsl:call-template>
140 </xsl:otherwise>
141 </xsl:choose>
142
143 </xsl:template>
144
145
146 <!-- ___________________________________________________________________________________________________ -->
147 <xsl:template match="*">
148 <sv:node>
149 <xsl:attribute name='sv:name'><xsl:value-of select='name()'/></xsl:attribute>
150 <xsl:for-each select='@*'>
151 <xsl:text>&#10; </xsl:text>
152 <sv:property>
153 <xsl:attribute name='sv:name'><xsl:value-of select='name()'/></xsl:attribute>
154 <xsl:if test='not(@sv:type)'>
155 <xsl:attribute name='sv:type'>
156 <xsl:choose>
157 <xsl:when test='name()="jcr:primaryType" or name()="jcr:mixinTypes"'>Name</xsl:when>
158 <xsl:otherwise>String</xsl:otherwise>
159 </xsl:choose>
160 </xsl:attribute>
161 </xsl:if>
162 <xsl:apply-templates select='@*'/>
163 <xsl:call-template name='values'/>
164 <xsl:text>&#10; </xsl:text>
165 </sv:property>
166 </xsl:for-each>
167 <xsl:apply-templates/>
168 </sv:node>
169 </xsl:template>
170
171 <!-- ___________________________________________________________________________________________________ -->
172 <xsl:template match="@*|node()[not(self::*)]">
173 <xsl:copy/>
174 </xsl:template>
175
176 <!-- ___________________________________________________________________________________________________ -->
177 <xsl:template match="*[not(s:list[@elem='property']) and ancestor::*/@jcr:primaryType='hippo:handle']">
178 <sv:node>
179 <xsl:attribute name='sv:name'><xsl:value-of select='name()'/></xsl:attribute>
180 <xsl:text>&#10; </xsl:text>
181 <sv:property sv:name="jcr:primaryType" sv:type="Name">
182 <sv:value>hippostd:html</sv:value>
183 <xsl:text>&#10; </xsl:text>
184 </sv:property>
185 <xsl:text>&#10; </xsl:text>
186 <sv:property sv:name="hippostd:content" sv:type="String">
187 <sv:value><xsl:apply-templates mode='value'/></sv:value>
188 <xsl:text>&#10; </xsl:text>
189 </sv:property>
190 <xsl:text>&#10; </xsl:text>
191 </sv:node>
192 </xsl:template>
193
194
195 <!-- ___________________________________________________________________________________________________ -->
196 <xsl:template match="h:*" mode='value'>
197 <xsl:text>&lt;</xsl:text><xsl:value-of select='local-name()'/>
198 <xsl:for-each select='@*'>
199 <xsl:text> </xsl:text><xsl:value-of select='local-name()'/><xsl:text>=</xsl:text>
200 <xsl:variable name='quote'>
201 <xsl:choose>
202 <xsl:when test='not(contains(., "&apos;"))'>'</xsl:when>
203 <xsl:when test="not(contains(., '&quot;'))">"</xsl:when>
204 <xsl:otherwise>
205 <xsl:message terminate="yes" >
206 Weird error: attribute value contains single as well as double quote!
207 </xsl:message>
208 </xsl:otherwise>
209 </xsl:choose>
210 </xsl:variable>
211 <xsl:value-of select='$quote'/><xsl:value-of select='.'/><xsl:value-of select='$quote'/>
212 </xsl:for-each><xsl:text>&gt;</xsl:text>
213 <xsl:apply-templates mode='value'/>
214 <xsl:text>&lt;/</xsl:text><xsl:value-of select='local-name()'/><xsl:text>&gt;</xsl:text>
215 </xsl:template>
216
217
218
219 <!-- ___________________________________________________________________________________________________ -->
220 </xsl:transform>

Properties

Name Value
svn:eol-style native
svn:keywords Id