Professional Documents
Culture Documents
054
055 <!-- Print show name with a link to the list above --
>
056
057 <h3><a name="{generate-id(name)}">
058 <xsl:value-of select="name" /></a></h3>
059
060 <!-- Here I create an img tag and add attributes to
it -->
061
062 <img>
063
064 <!-- Select the attribute to change -->
065
066 <xsl:attribute name="src">
067
068 <!-- Set the value for the attribute -->
069 <!-- You grab the attribute of a node with @ -->
070
071 <xsl:value-of select="poster/@href" />
072 </xsl:attribute>
073 </img><br />
074
075 <!-- Returns the current node information -->
076
077 <xsl:value-of select="current()"/>
078
079 <p>The show <xsl:value-of select="name"/> was
released in
080 <xsl:value-of select="release"/> by
081 <xsl:value-of select="network"/>. It had an average
082 viewership of <xsl:value-of select="viewers"/>
million people.
083 It was cancelled in <xsl:value-of select="end_date"/>
084 </p><br />
085
086 </xsl:for-each>
087
088 <!-- Output Information in a table -->
089
090 <table border="2">
091 <tr><th>Name</th><th>Network</th><th>Viewers</th></tr>
092 <xsl:for-each select="tvshow/show">
093
094 <!-- Checks if the attribute of network is not equal to
UK -->
095
096 <!-- This will only allow non-UK shows on the list -->
097
098 <!-- You can use: = != > < -->
099
100 <!-- <xsl:if test="network[@country='UK']"> -->
101
102 <!-- Shows results when release < 2006 -->
103
104 <xsl:if test="release < 2006">
105
106 <tr>
107 <td><xsl:value-of select="name"/></td>
108 <td><xsl:value-of select="network"/></td>
109 <td><xsl:value-of select="viewers"/></td>
110 </tr>
www.newthinktank.com/2012/05/xml-video-tutorial-2/ 2/3
5/15/2019 XML Video Tutorial 2
111
112 </xsl:if>
113
114 <!-- xsl:choose is used to cover many conditions -->
115
116 <xsl:choose>
117
118 <!-- xsl:when defines under what condition to execute
-->
119
120 <xsl:when test="release > 2006">
121
122 <tr bgcolor="yellow">
123 <td><xsl:value-of select="name"/></td>
124 <td><xsl:value-of select="network"/></td>
125 <td><xsl:value-of select="viewers"/></td>
126 </tr>
127
128 </xsl:when>
129
130 <xsl:when test="release = 2006">
131
132 <tr bgcolor="orange">
133 <td><xsl:value-of select="name"/></td>
134 <td><xsl:value-of select="network"/></td>
135 <td><xsl:value-of select="viewers"/></td>
136 </tr>
137
138 </xsl:when>
139
140 <!-- If xsl:if was removed this would be the default
action for xsl:choose -->
141
142 <xsl:otherwise>
143
144 <tr bgcolor="pink">
145 <td><xsl:value-of select="name"/></td>
146 <td><xsl:value-of select="network"/></td>
147 <td><xsl:value-of select="viewers"/></td>
148 </tr>
149
150 </xsl:otherwise>
151
152 </xsl:choose>
153
154 </xsl:for-each>
155 </table>
156
157 </body>
158 </html>
159
160 </xsl:template>
161
162 </xsl:stylesheet>
www.newthinktank.com/2012/05/xml-video-tutorial-2/ 3/3