|
[x]
Posted via EE Mobile
|
|
| Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again. |
|
|
|
|
Asked by RosaV in Extensible Stylesheet Language Transformation (XSLT), XSL Formatting Objects
I'm kind of confused about xsl and xml transformation subject.
This program supposed to display in the browser as a table and sort by the number of pages, rather than by chapter number, but whenever I tried to load it, all I see is the code. Am I missing something or my xsl is not well formatted. If you can help me. I will appreciated.
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:
|
xml code
<?xml version = "1.0"?>
<?xml-stylesheet type = "text/xsl" href = "sorting_byPage.xsl"?>
<!-- Fig. 14.22 sorting.xml -->
<!-- XML document containing book information -->
<book isbn = "999-99999-9-X">
<title>Deitel's XML Primer</title>
<author>
<firstName>Jane</firstName>
<lastName>Blue</lastName>
</author>
<chapters>
<frontMatter>
<preface pages = "2" />
<contents pages = "5" />
<illustrations pages = "4" />
</frontMatter>
<chapter number = "3" pages = "44">Advanced XML</chapter>
<chapter number = "2" pages = "35">Intermediate XML</chapter>
<appendix number = "B" pages = "26">Parsers and Tools</appendix>
<appendix number = "A" pages = "7">Entities</appendix>
<chapter number = "1" pages = "28">XML Fundamentals</chapter>
</chapters>
<media type = "CD" />
</book>
xsl code
<?xml version="1.0"?>
<!-- Fig. 14.23: sorting_byPage.xsl -->
<!-- Transformation of book information into XHTML -->
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<!-- write XML declaration and DOCTYPE DTD information -->
<xsl:output method="html" omit-xml-declaration="no"
doctype-system="http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"
doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN" />
<!-- match document root -->
<xsl:template match="/">
<html xmlns="http://www.w3.org/1999/xhtml">
<xsl:apply-templates />
</html>
</xsl:template>
<!-- match book -->
<xsl:template match="book">
<head>
<title>ISBN <xsl:value-of select="@isbn" /> -
<xsl:value-of select="title" />
</title>
</head>
<body>
<h1 style="color: blue"><xsl:value-of select="title" /></h1>
<h2 style="color: blue">by
<xsl:value-of select="author/lastName" />,
<xsl:value-of select="author/firstName" /></h2>
<table style="border-style: groove; background-color: wheat">
<xsl:for-each select="chapters/frontMatter/*">
<tr>
<td style="text-align: right">
<xsl:value-of select="name()" />
</td>
<td>
( <xsl:value-of select="@pages" /> pages )
</td>
</tr>
</xsl:for-each>
<xsl:for-each select="chapters/chapter">
<xsl:sort select="@pages" data-type="number" order="descending" />
<tr>
<td style="text-align: right">
Chapter <xsl:value-of select="@number" />
</td>
<td>
<xsl:value-of select="text()" />
( <xsl:value-of select="@pages" /> pages )
</td>
</tr>
</xsl:for-each>
<xsl:for-each select="chapters/appendix">
<xsl:sort select="@number" data-type="text" order="ascending" />
<tr>
<td style="text-align: right">
Appendix <xsl:value-of select="@number" />
</td>
<td>
<xsl:value-of select="text()" />
( <xsl:value-of select="@pages" /> pages )
</td>
</tr>
</xsl:for-each>
</table>
<br /> <p style="color: blue">Pages:
<xsl:variable name="pagecount"
select="sum(chapters//*/@pages)" />
<xsl:value-of select="$pagecount" />
<br />Media Type: <xsl:value-of select="media/@type" /></p>
</body>
</xsl:template>
</xsl:stylesheet>
|
20091021-EE-VQP-81 - Hierarchy / EE_QW_3_20080625