4 * The contents of this file are subject to the Mozilla Public
5 * License Version 1.1 (the "License"); you may not use this file
6 * except in compliance with the License. You may obtain a copy of
7 * the License at http://www.mozilla.org/MPL/
9 * Software distributed under the License is distributed on an "AS
10 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
11 * implied. See the License for the specific language governing
12 * rights and limitations under the License.
14 * The Original Code is XSL:P XSLT processor.
16 * The Initial Developer of the Original Code is Keith Visco.
17 * Portions created by Keith Visco (C) 1999 Keith Visco.
18 * All Rights Reserved..
21 * Keith Visco, kvisco@ziplink.net
28 This is a test stylesheet used for testing the XSL processor
31 <xsl:stylesheet xmlns:
xsl=
"http://www.w3.org/1999/XSL/Transform" version=
"1.0">
33 <!-- set the output properties -->
34 <xsl:output method=
"html"/>
37 <xsl:attribute-set name=
"style1">
38 <xsl:attribute name=
"COLOR">blue
</xsl:attribute>
39 <xsl:attribute name=
"SIZE">+
0</xsl:attribute>
42 <xsl:attribute-set name=
"style2">
43 <xsl:attribute name=
"COLOR">red
</xsl:attribute>
44 <xsl:attribute name=
"SIZE">+
0</xsl:attribute>
48 <xsl:template match=
"/">
49 <xsl:processing-instruction name=
"foo">
50 this is a test processing instruction
51 </xsl:processing-instruction>
52 <xsl:comment>TransforMiiX Test cases, written by Keith Visco.
</xsl:comment>
53 <xsl:apply-templates/>
56 <!-- named template -->
57 <xsl:template name=
"named-template-test">
58 <xsl:param name=
"my-param" select=
"'default value'"/>
59 named template processed with
<xsl:text> </xsl:text>
60 <xsl:value-of select=
"$my-param"/>!
61 <xsl:if test=
"$dummy-param">
64 Error, undeclared parameters should be ignored!
69 <!-- empty variable for named template test -->
70 <xsl:variable name=
"dummy-param" />
72 <!-- supress non-selected nodes-->
73 <xsl:template match=
"*"/>
75 <!-- variable tests -->
76 <xsl:variable name=
"product-name">
77 Transfor
<FONT COLOR=
"blue">Mii
</FONT>X
79 <!-- main rule for document element -->
80 <xsl:template match=
"document">
83 <TITLE>TransforMiiX Test Cases
</TITLE>
84 <SCRIPT Language=
"JavaScript">
86 // Support for Apple's DumpRenderTree
87 if (window.testRunner)
88 testRunner.dumpAsText();
89 // This is a test for properly printing SCRIPT elements
90 // currently there is a bug, so use xsl:text as a wrapper as I
101 <BODY BGColor=
"#FFFFFF" Text=
"#000000">
103 <FONT COLOR=
"BLUE" FACE=
"Arial" SIZE=
"+1">
107 <B>Transfor
<FONT COLOR=
"blue">Mii
</FONT>X Test Cases
</B>
110 This document serves to test basic XSL expressions.
114 <B>Testing xsl:variable and xsl:copy-of
</B><BR/>
115 <B>Test:
</B> <xsl:copy-of
select=
"$product-name"/
><BR/>
116 <B>Desired Result:
</B>Transfor
<FONT COLOR=
"blue">Mii
</FONT>X
<BR/>
117 <B>Result:
</B><xsl:copy-of select=
"$product-name"/>
121 <B>Testing xsl:if
</B><BR/>
122 <B>Test:
</B> <xsl:if
test=
"x | y | z">true
</xsl:if
><BR/>
123 <B>Desired Result:
</B> true
<BR/>
124 <B>Result:
</B> <xsl:if test=
"x | y | z">true
</xsl:if>
129 <B>Testing xsl:if
</B><BR/>
130 <B>Test:
</B> <xsl:if
test=
"true()">true
</xsl:if
><BR/>
131 <B>Desired Result:
</B> true
<BR/>
132 <B>Result:
</B> <xsl:if test=
"true()">true
</xsl:if>
137 <B>Testing xsl:if
</B><BR/>
138 <B>Test:
</B> <xsl:if
test=
"'a'='b'">a equals b
</xsl:if
><BR/>
139 <B></B> <xsl:if
test=
"'a'!='b'">a does not equal b
</xsl:if
>
141 <B>Desired Result:
</B> a does not equal to b
<BR/>
143 <xsl:if test=
"'a'='b'">a equals b
<BR/></xsl:if>
144 <xsl:if test=
"'a'!='b'">a does not equal b
</xsl:if>
149 <B>Testing xsl:if
</B><BR/>
150 <B>Test:
</B> <xsl:if
test=
"2+1-3"> 2+
1-
3 is true
</xsl:if
><BR/>
151 <B> </B><xsl:if
test=
"not(2+1-3)"> not(
2+
1-
3) is true
</xsl:if
><BR/>
152 <B>Desired Result:
</B>not(
2+
1-
3) is true
<BR/>
154 <xsl:if test=
"2+1-3">2+
1-
3 is true
</xsl:if>
155 <xsl:if test=
"not(2+1-3)">not(
2+
1-
3) is true
</xsl:if>
160 <B>Testing xsl:choose
</B><BR/>
161 <B>Test:
</B>see source
<BR/>
162 <B>Desired Result:
</B> true
<BR/>
165 <xsl:when test=
"a">error - a
</xsl:when>
166 <xsl:when test=
"abc/def">true
</xsl:when>
167 <xsl:when test=
"b">error - b
</xsl:when>
168 <xsl:otherwise>false
</xsl:otherwise>
173 <B>Testing parent and ancestor ops
</B><BR/>
174 <B>Test:
</B>see source
<BR/>
175 <B>Desired Result:
</B> true
<BR/>
176 <B>Result:
</B><xsl:if test=
"//def">true
</xsl:if><BR/>
182 <B>Testing basic xsl:apply-templates
</B><BR/>
183 <B>Test:
</B><xsl:apply-templates/
><BR/>
184 <B>Desired Result:
</B>element
<B>x
</B>, element
<B>y
</B>, element
<B>z
</B><BR/>
185 <B>Result:
</B><xsl:apply-templates select=
"x|y|z"/>
190 <B>Testing basic xsl:apply-templates with mode
</B><BR/>
191 <B>Test:
</B><xsl:apply-templates
mode=
"mode-test"/
><BR/>
192 <B>Desired Result:
</B>x, y, z
<BR/>
193 <B>Result:
</B><xsl:apply-templates select=
"x|y|z" mode=
"mode-test"/>
197 <B>Testing predicates
</B><BR/>
198 <B>Test:
</B>see source
<BR/>
199 <B>Desired Result:
</B> <B>z
</B><BR/>
201 <xsl:for-each select=
"*[position()=3]">
202 <B><xsl:value-of select=
"."/></B>
207 <B>Testing predicates
</B><BR/>
208 <B>Test:
</B>see source
<BR/>
209 <B>Desired Result:
</B><BR/>
211 <xsl:for-each select=
"*[false()]">
212 <B><xsl:value-of select=
"."/></B>
217 <B>Named Template/Call Template
</B>
219 <B>Test:
</B><xsl:call-template
name=
"named-template-test"/
><BR/>
220 <B>Desired Result:
</B>named template processed with default value!
<BR/>
221 <B>Result:
</B><xsl:call-template name=
"named-template-test"/>
224 <B>Test:
</B> - passing arguments to named templates (see xsl source)
<BR/>
225 <B>Desired Result:
</B>named template processed with passed value!
<BR/>
227 <xsl:call-template name=
"named-template-test">
228 <xsl:with-param name=
"my-param" select=
"'passed value'"/>
229 <xsl:with-param name=
"dummy-param" select=
"'test'"/>
235 <B>Attribute Value Templates and variables
</B><BR/>
238 <xsl:variable
name=
"color">red
</xsl:variable
><BR/>
239 <FONT
COLOR=
"{$color}">Red Text
</FONT
>
241 <B>Desired Result:
</B>
242 <FONT COLOR=
"red">Red Text
</FONT><BR/>
244 <xsl:variable name=
"color">red
</xsl:variable>
245 <FONT COLOR=
"{$color}">Red Text
</FONT>
248 <!-- AXIS IDENTIFIER TESTS -->
250 <TR BGColor=
"#E0E0FF">
251 <TD Colspan=
"2" ALIGN=
"CENTER">
252 <B>Axis Identifiers (these should work, I need more test cases though)
</B>
257 <TD VALIGN=
"TOP"><B>Test:
</B></TD>
259 <xsl:if
test=
"descendant::z">true
</xsl:if
><BR />
263 <TD><B>Desired Result:
</B></TD>
265 <FONT COLOR=
"blue">true
</FONT><BR/>
269 <TD><B>Result:
</B></TD>
271 <xsl:if test=
"descendant::z">
272 <FONT COLOR=
"blue">true
</FONT>
278 <TD VALIGN=
"TOP"><B>Test:
</B></TD>
280 <xsl:if
test=
"not(descendant-or-self::no-element)">true
</xsl:if
><BR />
284 <TD><B>Desired Result:
</B></TD>
286 <FONT COLOR=
"blue">true
</FONT><BR/>
290 <TD><B>Result:
</B></TD>
292 <xsl:if test=
"not(descendant-or-self::no-element)">
293 <FONT COLOR=
"blue">true
</FONT>
299 <TD VALIGN=
"TOP"><B>Test:
</B></TD>
301 <xsl:value-of
select=
"count(x/attribute::*)"/
><BR />
305 <TD><B>Desired Result:
</B></TD>
307 <FONT COLOR=
"blue">1</FONT><BR/>
311 <TD><B>Result:
</B></TD>
313 <FONT COLOR=
"blue"><xsl:value-of select=
"count(x/attribute::*)"/></FONT>
320 <TR BGColor=
"#E0E0FF">
321 <TD Colspan=
"2" ALIGN=
"CENTER">
322 <B>Creating Elements with xsl:element and xsl:attribute
</B>
327 <TD VALIGN=
"TOP"><B>Test:
</B></TD>
329 <xsl:element
name=
"FONT"><BR />
330 <xsl:attribute
name=
"COLOR">blue
</xsl:attribute
> <BR/>
336 <TD><B>Desired Result:
</B></TD>
338 <FONT COLOR=
"blue">Passed
</FONT><BR/>
342 <TD><B>Result:
</B></TD>
344 <xsl:element name=
"FONT">
345 <xsl:attribute name=
"COLOR">blue
</xsl:attribute>
351 <TR BGCOLOR=
"#E0E0FF" ALIGN=
"CENTER">
352 <TD COLSPAN=
"2"><B>Using Attribute Sets
</B></TD>
355 <TD VALIGN=
"TOP"><B>Test:
</B></TD>
357 <FONT xsl:
use-attribute-sets=
"style1"><BR />
363 <TD><B>Desired Result:
</B></TD>
365 <FONT COLOR=
"blue">Passed
</FONT><BR/>
369 <TD><B>Result:
</B></TD>
371 <FONT xsl:
use-attribute-sets=
"style1">
378 <TD VALIGN=
"TOP"><B>Test:
</B></TD>
380 <xsl:element
name=
"FONT" use-attribute-sets=
"style1 style2"><BR />
386 <TD><B>Desired Result:
</B></TD>
388 <FONT COLOR=
"red">Passed
</FONT><BR/>
392 <TD><B>Result:
</B></TD>
394 <xsl:element name=
"FONT" use-attribute-sets=
"style1 style2">
401 <!-- NUMBERING Examples -->
403 <TR BGColor=
"#E0E0FF">
404 <TD Colspan=
"2" ALIGN=
"CENTER">
405 <B>Numbering (only simple numbering currently implemented)
</B>
410 <TD VALIGN=
"TOP"><B>Test:
</B></TD>
412 <xsl:number
value=
"4"/
><BR />
416 <TD><B>Desired Result:
</B></TD>
418 <FONT COLOR=
"blue">4</FONT><BR/>
422 <TD><B>Result:
</B></TD>
424 <FONT COLOR=
"blue"><xsl:number value=
"4"/></FONT>
429 <TD VALIGN=
"TOP"><B>Test:
</B></TD>
435 <TD><B>Desired Result:
</B></TD>
438 1. x
<BR/>1. y
<BR/>1. z
443 <TD><B>Result:
</B></TD>
446 <xsl:for-each select=
"x | y | z">
448 <xsl:text>.
</xsl:text><xsl:value-of select=
"."/><BR/>
457 <!-- ADDITIVE EXPRESSION TESTS -->
459 <TR BGColor=
"#E0E0FF">
460 <TD Colspan=
"2" ALIGN=
"CENTER">
461 <B>Additive Expressions
</B>
466 <TD VALIGN=
"TOP"><B>Test:
</B></TD>
468 <xsl:value-of
select=
"70+4"/
><BR />
472 <TD><B>Desired Result:
</B></TD>
474 <FONT COLOR=
"blue">74</FONT><BR/>
478 <TD><B>Result:
</B></TD>
481 <xsl:value-of select=
"70+4"/>
487 <TD VALIGN=
"TOP"><B>Test:
</B></TD>
489 <xsl:value-of
select=
"-70+4"/
><BR />
493 <TD><B>Desired Result:
</B></TD>
495 <FONT COLOR=
"blue">-
66</FONT><BR/>
499 <TD><B>Result:
</B></TD>
502 <xsl:value-of select=
"-70+4"/>
507 <TD VALIGN=
"TOP"><B>Test:
</B></TD>
509 <xsl:value-of
select=
"1900+70+8-4"/
><BR />
513 <TD><B>Desired Result:
</B></TD>
515 <FONT COLOR=
"blue">1974</FONT><BR/>
519 <TD><B>Result:
</B></TD>
522 <xsl:value-of select=
"1900+70+8-4"/>
527 <TD VALIGN=
"TOP"><B>Test:
</B></TD>
529 <xsl:value-of
select=
"(4+5)-(9+9)"/
><BR />
533 <TD><B>Desired Result:
</B></TD>
535 <FONT COLOR=
"blue">-
9</FONT><BR/>
539 <TD><B>Result:
</B></TD>
542 <xsl:value-of select=
"(4+5)-(9+9)"/>
549 <!-- MULTIPLICATIVE EXPRESSION TESTS -->
551 <TR BGColor=
"#E0E0FF">
552 <TD Colspan=
"2" ALIGN=
"CENTER">
553 <B>Multiplicative Expressions
</B>
558 <TD VALIGN=
"TOP"><B>Test:
</B></TD>
560 <xsl:value-of
select=
"7*4"/
><BR />
564 <TD><B>Desired Result:
</B></TD>
566 <FONT COLOR=
"blue">28</FONT><BR/>
570 <TD><B>Result:
</B></TD>
573 <xsl:value-of select=
"7*4"/>
579 <TD VALIGN=
"TOP"><B>Test:
</B></TD>
581 <xsl:value-of
select=
"7mod 4"/
><BR />
585 <TD><B>Desired Result:
</B></TD>
587 <FONT COLOR=
"blue">3</FONT><BR/>
591 <TD><B>Result:
</B></TD>
594 <xsl:value-of select=
"7mod 4"/>
600 <TD VALIGN=
"TOP"><B>Test:
</B></TD>
602 <xsl:value-of
select=
"7div 4"/
><BR />
606 <TD><B>Desired Result:
</B></TD>
608 <FONT COLOR=
"blue">1.75</FONT><BR/>
612 <TD><B>Result:
</B></TD>
615 <xsl:value-of select=
"7div 4"/>
621 <TD VALIGN=
"TOP"><B>Test:
</B></TD>
623 <xsl:value-of
select=
"7div 0"/
><BR />
627 <TD><B>Desired Result:
</B></TD>
629 <FONT COLOR=
"blue">Infinity
</FONT><BR/>
633 <TD><B>Result:
</B></TD>
636 <xsl:value-of select=
"7div 0"/>
642 <TD VALIGN=
"TOP"><B>Test:
</B></TD>
644 <xsl:value-of
select=
"0 div 0"/
><BR />
648 <TD><B>Desired Result:
</B></TD>
650 <FONT COLOR=
"blue">NaN
</FONT><BR/>
654 <TD><B>Result:
</B></TD>
657 <xsl:value-of select=
"0 div 0"/>
664 <TD VALIGN=
"TOP"><B>Test:
</B></TD>
666 <xsl:variable
name=
"x" select=
"7*3"/
><BR />
667 <xsl:variable
name=
"y" select=
"3"/
><BR />
668 <xsl:value-of
select=
"$x div $y"/
><BR />
672 <TD><B>Desired Result:
</B></TD>
674 <FONT COLOR=
"blue">7</FONT><BR/>
678 <TD><B>Result:
</B></TD>
681 <xsl:variable name=
"x" select=
"7*3"/>
682 <xsl:variable name=
"y" select=
"3"/>
683 <xsl:value-of select=
"$x div $y"/>
690 <!-- PRECEDENCE TESTS -->
692 <TR BGColor=
"#E0E0FF">
693 <TD Colspan=
"2" ALIGN=
"CENTER">
694 <B>Precedence tests
</B>
699 <TD VALIGN=
"TOP"><B>Test:
</B></TD>
701 <xsl:value-of
select=
"2 mod 2 = 0"/
><BR />
705 <TD><B>Desired Result:
</B></TD>
707 <FONT COLOR=
"blue">true
</FONT><BR/>
711 <TD><B>Result:
</B></TD>
714 <xsl:value-of select=
"2 mod 2 = 0"/>
720 <TD VALIGN=
"TOP"><B>Test:
</B></TD>
722 <xsl:value-of
select=
"5 mod 2 < 5 and 2*6 >= 12"/
><BR />
726 <TD><B>Desired Result:
</B></TD>
728 <FONT COLOR=
"blue">true
</FONT><BR/>
732 <TD><B>Result:
</B></TD>
735 <xsl:value-of select=
"5 mod 2 < 5 and 2*6>=12"/>
741 <TD VALIGN=
"TOP"><B>Test:
</B></TD>
743 <xsl:value-of
select=
"5 mod 2 < 5 and 2*6>12"/
><BR />
747 <TD><B>Desired Result:
</B></TD>
749 <FONT COLOR=
"blue">false
</FONT><BR/>
753 <TD><B>Result:
</B></TD>
756 <xsl:value-of select=
"5 mod 2 < 5 and 2*6>12"/>
763 <TD VALIGN=
"TOP"><B>Test:
</B></TD>
765 <xsl:value-of
select=
"4+5*3"/
><BR />
769 <TD><B>Desired Result:
</B></TD>
771 <FONT COLOR=
"blue">19</FONT><BR/>
775 <TD><B>Result:
</B></TD>
778 <xsl:value-of select=
"4+5*3"/>
784 <TD VALIGN=
"TOP"><B>Test:
</B></TD>
786 <xsl:value-of
select=
"4+5*3+(6-4)*7"/
><BR />
790 <TD><B>Desired Result:
</B></TD>
792 <FONT COLOR=
"blue">33</FONT><BR/>
796 <TD><B>Result:
</B></TD>
799 <xsl:value-of select=
"4+5*3+(6-4)*7"/>
805 <!-- Result Type conversion tests -->
807 <TR BGColor=
"#E0E0FF">
808 <TD Colspan=
"2" ALIGN=
"CENTER">
809 <B>Automatic Result Type Conversion
</B>
814 <TD VALIGN=
"TOP"><B>Test:
</B></TD>
816 <xsl:value-of
select=
"'747' + 8"/
><BR />
820 <TD><B>Desired Result:
</B></TD>
822 <FONT COLOR=
"blue">755</FONT><BR/>
826 <TD><B>Result:
</B></TD>
829 <xsl:value-of select=
"'747' + 8"/>
838 <!-- simple union expressions -->
839 <xsl:template match=
"x | y | z" priority=
"1.0">
840 element
<B><xsl:text> </xsl:text><xsl:value-of select=
"@*"/></B>
841 <xsl:if test=
"not(position()=3)">,
</xsl:if>
844 <xsl:template match=
"x | y | z" mode=
"mode-test">
845 <xsl:value-of select=
"@*"/>
846 <xsl:if test=
"not(position()=3)"><xsl:text>,
</xsl:text></xsl:if>
849 <xsl:template match=
"z">
850 element (z):
<B><xsl:value-of select=
"."/></B>