Skip to content

Commit 7a47170

Browse files
committed
XSL: Moved main template to the top.
1 parent 317981b commit 7a47170

1 file changed

Lines changed: 144 additions & 144 deletions

File tree

entries2html.xsl

Lines changed: 144 additions & 144 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,149 @@
1-
<xsl:stylesheet version='1.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>
1+
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
22
<xsl:output method="html" omit-xml-declaration="yes"/>
33

4+
<xsl:template match="/">
5+
<script>{
6+
"title":
7+
<xsl:call-template name="escape-string">
8+
<xsl:with-param name="s" select="//entry/title/text()"/>
9+
</xsl:call-template>,
10+
"excerpt":
11+
<xsl:call-template name="escape-string">
12+
<xsl:with-param name="s" select="//entry[1]/desc/text()|//entry[1]/desc/*"/>
13+
</xsl:call-template>,
14+
"termSlugs": {
15+
"category": [
16+
<xsl:for-each select="//entry/category">
17+
<xsl:if test="position() &gt; 1"><xsl:text>,</xsl:text></xsl:if>
18+
<xsl:text>"</xsl:text>
19+
<xsl:value-of select="@slug"/>
20+
<xsl:text>"</xsl:text>
21+
</xsl:for-each>
22+
]
23+
}
24+
}</script>
25+
26+
<xsl:if test="count(//entry) &gt; 1">
27+
<xsl:call-template name="toc"/>
28+
</xsl:if>
29+
30+
<xsl:for-each select="//entry">
31+
<xsl:variable name="entry-name" select="@name"/>
32+
<xsl:variable name="entry-name-trans" select="translate($entry-name,'$., ()/{}','s---')"/>
33+
<xsl:variable name="entry-type" select="@type"/>
34+
<xsl:variable name="entry-index" select="position()"/>
35+
<xsl:variable name="entry-pos" select="concat($entry-name-trans,$entry-index)"/>
36+
<xsl:variable name="number-examples" select="count(example)"/>
37+
38+
<xsl:if test="./added">
39+
<span class="versionAdded">version added: <xsl:value-of select="added"/></span>
40+
</xsl:if>
41+
42+
<article>
43+
<xsl:attribute name="id">
44+
<xsl:value-of select="$entry-pos"/>
45+
</xsl:attribute>
46+
<xsl:attribute name="class">
47+
<xsl:value-of select="concat('entry ', $entry-type)"/>
48+
</xsl:attribute>
49+
50+
<xsl:call-template name="entry-title"/>
51+
52+
<div class="jq-box roundBottom entry-details">
53+
<xsl:call-template name="entry-body"/>
54+
55+
<xsl:if test="normalize-space(longdesc/*)">
56+
<div class="longdesc">
57+
<xsl:copy-of select="longdesc/*" />
58+
</div>
59+
</xsl:if>
60+
61+
<xsl:if test="note">
62+
<h3>Additional Notes:</h3>
63+
<div class="longdesc">
64+
<ul>
65+
<xsl:for-each select="note">
66+
<li><xsl:apply-templates select="."/></li>
67+
</xsl:for-each>
68+
</ul>
69+
</div>
70+
</xsl:if>
71+
72+
<xsl:if test="$number-examples &gt; 0">
73+
<div id="examples">
74+
<h3>Example<xsl:if test="$number-examples &gt; 1">s</xsl:if>:</h3>
75+
<div class="entry-examples">
76+
<xsl:attribute name="id">
77+
<xsl:text>entry-examples</xsl:text>
78+
<xsl:if test="$entry-index &gt; 1">
79+
<xsl:text>-</xsl:text><xsl:value-of select="$entry-index - 1"/>
80+
</xsl:if>
81+
</xsl:attribute>
82+
<xsl:for-each select="example">
83+
<div class="entry-example">
84+
<xsl:attribute name="id">
85+
<xsl:text>example-</xsl:text>
86+
<xsl:if test="$entry-index &gt; 1">
87+
<xsl:value-of select="$entry-index - 1"/>
88+
<xsl:text>-</xsl:text>
89+
</xsl:if>
90+
<xsl:value-of select="position() - 1"/>
91+
</xsl:attribute>
92+
<h4><xsl:if test="$number-examples &gt; 1">Example: </xsl:if><span class="desc"><xsl:value-of select="desc" /></span></h4>
93+
<pre><code data-linenum="true"><xsl:choose>
94+
<xsl:when test="html">&lt;!DOCTYPE html&gt;
95+
&lt;html&gt;
96+
&lt;head&gt;<xsl:if test="css/text()">
97+
&lt;style&gt;<xsl:copy-of select="css/text()" />&lt;/style&gt;</xsl:if>
98+
&lt;script src="http://code.jquery.com/jquery-latest.js"&gt;&lt;/script&gt;<xsl:if test="code/@location='head'">
99+
&lt;script&gt;
100+
<xsl:copy-of select="code/text()" />
101+
&lt;/script&gt;
102+
</xsl:if>
103+
&lt;/head&gt;
104+
&lt;body&gt;
105+
<xsl:copy-of select="html/text()" />
106+
<xsl:choose>
107+
<xsl:when test="code/@location='head'"></xsl:when>
108+
<xsl:otherwise>
109+
&lt;script&gt;<xsl:copy-of select="code/text()" />&lt;/script&gt;</xsl:otherwise>
110+
</xsl:choose>
111+
112+
&lt;/body&gt;
113+
&lt;/html&gt;</xsl:when>
114+
<xsl:otherwise>
115+
<xsl:attribute name="class">example</xsl:attribute>
116+
<xsl:copy-of select="code/text()" />
117+
</xsl:otherwise>
118+
</xsl:choose></code></pre>
119+
120+
<xsl:if test="html">
121+
<h4>Demo:</h4>
122+
<div class="demo code-demo">
123+
<xsl:if test="height">
124+
<xsl:attribute name="data-height">
125+
<xsl:value-of select="height"/>
126+
</xsl:attribute>
127+
</xsl:if>
128+
</div>
129+
</xsl:if>
130+
131+
<xsl:if test="results">
132+
<h4>Result:</h4>
133+
<pre><code class="results">
134+
<xsl:value-of select="results"/>
135+
</code></pre>
136+
</xsl:if>
137+
</div>
138+
</xsl:for-each>
139+
</div>
140+
</div>
141+
</xsl:if>
142+
</div>
143+
</article>
144+
</xsl:for-each>
145+
</xsl:template>
146+
4147
<xsl:template match="option|property">
5148
<h5 class="option">
6149
<xsl:value-of select="@name" />
@@ -361,149 +504,6 @@
361504
</ul>
362505
</xsl:template>
363506

364-
<xsl:template match="/">
365-
<script>{
366-
"title":
367-
<xsl:call-template name="escape-string">
368-
<xsl:with-param name="s" select="//entry/title/text()"/>
369-
</xsl:call-template>,
370-
"excerpt":
371-
<xsl:call-template name="escape-string">
372-
<xsl:with-param name="s" select="//entry[1]/desc/text()|//entry[1]/desc/*"/>
373-
</xsl:call-template>,
374-
"termSlugs": {
375-
"category": [
376-
<xsl:for-each select="//entry/category">
377-
<xsl:if test="position() &gt; 1"><xsl:text>,</xsl:text></xsl:if>
378-
<xsl:text>"</xsl:text>
379-
<xsl:value-of select="@slug"/>
380-
<xsl:text>"</xsl:text>
381-
</xsl:for-each>
382-
]
383-
}
384-
}</script>
385-
386-
<xsl:if test="count(//entry) &gt; 1">
387-
<xsl:call-template name="toc"/>
388-
</xsl:if>
389-
390-
<xsl:for-each select="//entry">
391-
<xsl:variable name="entry-name" select="@name"/>
392-
<xsl:variable name="entry-name-trans" select="translate($entry-name,'$., ()/{}','s---')"/>
393-
<xsl:variable name="entry-type" select="@type"/>
394-
<xsl:variable name="entry-index" select="position()"/>
395-
<xsl:variable name="entry-pos" select="concat($entry-name-trans,$entry-index)"/>
396-
<xsl:variable name="number-examples" select="count(example)"/>
397-
398-
<xsl:if test="./added">
399-
<span class="versionAdded">version added: <xsl:value-of select="added"/></span>
400-
</xsl:if>
401-
402-
<div>
403-
<xsl:attribute name="id">
404-
<xsl:value-of select="$entry-pos"/>
405-
</xsl:attribute>
406-
<xsl:attribute name="class">
407-
<xsl:value-of select="concat('entry ', $entry-type)"/>
408-
</xsl:attribute>
409-
410-
<xsl:call-template name="entry-title"/>
411-
412-
<div class="jq-box roundBottom entry-details">
413-
<xsl:call-template name="entry-body"/>
414-
415-
<xsl:if test="normalize-space(longdesc/*)">
416-
<div class="longdesc">
417-
<xsl:copy-of select="longdesc/*" />
418-
</div>
419-
</xsl:if>
420-
<xsl:if test="note">
421-
<h3>Additional Notes:</h3>
422-
<div class="longdesc">
423-
<ul>
424-
<xsl:for-each select="note">
425-
<li><xsl:apply-templates select="."/></li>
426-
</xsl:for-each>
427-
</ul>
428-
</div>
429-
</xsl:if>
430-
<xsl:if test="$number-examples &gt; 0">
431-
<div id="examples">
432-
<h3>Example<xsl:if test="$number-examples &gt; 1">s</xsl:if>:</h3>
433-
<div class="entry-examples">
434-
<xsl:attribute name="id">
435-
<xsl:text>entry-examples</xsl:text>
436-
<xsl:if test="$entry-index &gt; 1">
437-
<xsl:text>-</xsl:text><xsl:value-of select="$entry-index - 1"/>
438-
</xsl:if>
439-
</xsl:attribute>
440-
<xsl:for-each select="example">
441-
<div class="entry-example">
442-
<xsl:attribute name="id">
443-
<xsl:text>example-</xsl:text>
444-
<xsl:if test="$entry-index &gt; 1">
445-
<xsl:value-of select="$entry-index - 1"/>
446-
<xsl:text>-</xsl:text>
447-
</xsl:if>
448-
<xsl:value-of select="position() - 1"/>
449-
</xsl:attribute>
450-
<h4><xsl:if test="$number-examples &gt; 1">Example: </xsl:if><span class="desc"><xsl:value-of select="desc" /></span></h4>
451-
<pre><code data-linenum="true"><xsl:choose>
452-
<xsl:when test="html">&lt;!DOCTYPE html&gt;
453-
&lt;html&gt;
454-
&lt;head&gt;<xsl:if test="css/text()">
455-
&lt;style&gt;<xsl:copy-of select="css/text()" />&lt;/style&gt;</xsl:if>
456-
&lt;script src="http://code.jquery.com/jquery-latest.js"&gt;&lt;/script&gt;<xsl:if test="code/@location='head'">
457-
&lt;script&gt;
458-
<xsl:copy-of select="code/text()" />
459-
&lt;/script&gt;
460-
</xsl:if>
461-
&lt;/head&gt;
462-
&lt;body&gt;
463-
<xsl:copy-of select="html/text()" />
464-
<xsl:choose>
465-
<xsl:when test="code/@location='head'"></xsl:when>
466-
<xsl:otherwise>
467-
&lt;script&gt;<xsl:copy-of select="code/text()" />&lt;/script&gt;</xsl:otherwise>
468-
</xsl:choose>
469-
470-
&lt;/body&gt;
471-
&lt;/html&gt;</xsl:when>
472-
<xsl:otherwise>
473-
<xsl:attribute name="class">example</xsl:attribute>
474-
<xsl:copy-of select="code/text()" />
475-
</xsl:otherwise>
476-
</xsl:choose></code></pre>
477-
478-
<xsl:if test="html">
479-
<h4>Demo:</h4>
480-
<div class="demo code-demo">
481-
<xsl:if test="height">
482-
<xsl:attribute name="data-height">
483-
<xsl:value-of select="height"/>
484-
</xsl:attribute>
485-
</xsl:if>
486-
</div>
487-
</xsl:if>
488-
489-
<xsl:if test="results">
490-
<h4>Result:</h4>
491-
<pre><code class="results">
492-
<xsl:value-of select="results"/>
493-
</code></pre>
494-
</xsl:if>
495-
496-
</div>
497-
</xsl:for-each>
498-
</div>
499-
</div>
500-
</xsl:if>
501-
</div>
502-
</div>
503-
</xsl:for-each>
504-
505-
</xsl:template>
506-
507507
<!-- escape-string, from xml2json.xsl -->
508508
<xsl:template name="escape-string"><xsl:param name="s"/><xsl:text>"</xsl:text><xsl:call-template name="escape-bs-string"><xsl:with-param name="s" select="$s"/></xsl:call-template><xsl:text>"</xsl:text></xsl:template><xsl:template name="escape-bs-string"><xsl:param name="s"/><xsl:choose><xsl:when test="contains($s,'\')"><xsl:call-template name="escape-quot-string"><xsl:with-param name="s" select="concat(substring-before($s,'\'),'\\')"/></xsl:call-template><xsl:call-template name="escape-bs-string"><xsl:with-param name="s" select="substring-after($s,'\')"/></xsl:call-template></xsl:when><xsl:otherwise><xsl:call-template name="escape-quot-string"><xsl:with-param name="s" select="$s"/></xsl:call-template></xsl:otherwise></xsl:choose></xsl:template><xsl:template name="escape-quot-string"><xsl:param name="s"/><xsl:choose><xsl:when test="contains($s,'&quot;')"><xsl:call-template name="encode-string"><xsl:with-param name="s" select="concat(substring-before($s,'&quot;'),'\&quot;')"/></xsl:call-template><xsl:call-template name="escape-quot-string"><xsl:with-param name="s" select="substring-after($s,'&quot;')"/></xsl:call-template></xsl:when><xsl:otherwise><xsl:call-template name="encode-string"><xsl:with-param name="s" select="$s"/></xsl:call-template></xsl:otherwise></xsl:choose></xsl:template><xsl:template name="encode-string"><xsl:param name="s"/><xsl:choose><!-- tab --><xsl:when test="contains($s,'&#x9;')"><xsl:call-template name="encode-string"><xsl:with-param name="s" select="concat(substring-before($s,'&#x9;'),'\t',substring-after($s,'&#x9;'))"/></xsl:call-template></xsl:when><!-- line feed --><xsl:when test="contains($s,'&#xA;')"><xsl:call-template name="encode-string"><xsl:with-param name="s" select="concat(substring-before($s,'&#xA;'),'\n',substring-after($s,'&#xA;'))"/></xsl:call-template></xsl:when><!-- carriage return --><xsl:when test="contains($s,'&#xD;')"><xsl:call-template name="encode-string"><xsl:with-param name="s" select="concat(substring-before($s,'&#xD;'),'\r',substring-after($s,'&#xD;'))"/></xsl:call-template></xsl:when><xsl:otherwise><xsl:value-of select="$s"/></xsl:otherwise></xsl:choose></xsl:template>
509509

0 commit comments

Comments
 (0)