6 задание. Исходный xml:
<?xml version="1.0"?> <root>
<color>blue</color> <color>navy</color> <color>yellow</color> <color>green</color> <color>lime</color> <color>red</color>
</root>
Содержательная часть xsl для преобразования:
<xsl:for-each select="//root/color"> <table><tr><td>
<xsl:attribute name="style">color:<xsl:value-of select="."/></xsl:attribute>
<xsl:value-of select="."/> </td></tr></table>
</xsl:for-each>
Результат:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="UTF-8" /> </head>
<body>
<table>
<tr>
<td style="color:blue">blue</td> </tr>
</table>
<table>
<tr>
<td style="color:navy">navy</td> </tr>
</table>
<table>
<tr>
<td style="color:yellow">yellow</td> </tr>
</table>
<table>
<tr>
<td style="color:green">green</td> </tr>
</table>
<table>
<tr>
<td style="color:lime">lime</td> </tr>
</table>
<table>
<tr>
<td style="color:red">red</td>
</tr>
</table>
</body>
</html>
Рисунок 6 Полученный html в браузере
7 задание. Исходный xml:
<?xml version="1.0"?> <list>
<entry name="A"/> <entry name="B"/> <entry name="C"/> <entry name="D"/>
</list>
Содержательная часть xsl для преобразования:
<p>
<xsl:for-each select="//list/entry"> <xsl:value-of select="@name"/>
<xsl:choose>
<xsl:when test="position() != last()">, </xsl:when> <xsl:when test="position() = last()">.</xsl:when>
</xsl:choose> </xsl:for-each>
</p>
Результат:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="UTF-8" /> </head>
<body>
<p>A, B, C, D.</p> </body>
</html>
Рисунок 7. Полученный html в браузере
Вывод
При выполнении лабораторной работы изучены и применены технологии XML\XMLT.