<xsl:stylesheet version='1.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform' xmlns='http://www.w3.org/TR/xhtml1/strict'>

<xsl:strip-space elements='doc chapter section'/>

<xsl:output method='xml' indent='yes' encoding='iso-8859-1' />

<xsl:template match='doc'>

<html>

<head>

<title>

<xsl:value-of select='title'/>

</title>

</head>

<body>

<xsl:apply-templates/>

</body>

</html>

</xsl:template>

<xsl:template match='doc/title'>

<h1> <xsl:apply-templates/> </h1>

</xsl:template>

<xsl:template match='chapter/title'>

<h2> <xsl:apply-templates/> </h2>

</xsl:template>

<xsl:template match='section/title'>

<h3> <xsl:apply-templates/> </h3>

</xsl:template>

<xsl:template match='para'>

<p> <xsl:apply-templates/> </p>

</xsl:template>

<xsl:template match='note'>

<p class='note'>

<b>NOTE: </b> <xsl:apply-templates/>

</p>

</xsl:template>

<xsl:template match='emph'>

<em> <xsl:apply-templates/> </em>

</xsl:template>

</xsl:stylesheet>

Со следующим входным документом

<!DOCTYPE doc SYSTEM «doc.dtd»>

<doc>

<title>Document Title</title>

<chapter>

<title>Chapter Title</title>

<section>

<title>Section Title</title>

<para>This is a test.</para>

<note>This is a note.</note>

</section>

<section>

<title>Another Section Title</title>

<para>This is <emph>another</emph> test.</para>

<note>This is another note.</note>

</section>

</chapter>

</doc>

стиль должен дать следующий результат

<?xml version='1.0' encoding='iso-8859-1'?>

<html xmlns='http://www.w3.org/TR/xhtml1/strict'> <head>

<title>Document Title</title>

</head>

<body>

<h1>Document Title</h1>

<h2>Chapter Title</h2>

<h3>Section Title</h3>

<p>This is a test.</p>

<p class='note'> <b>NOTE: </b>This is a note.</p>

<h3>Another Section Title</h3>

<p>This is <em>another</em> test.</p>

<p class='note'> <b>NOTE: </b>This is another note.</p>

</body>

</html>

d.2 Пример данных

Для неких данных, представленных в формате XML, данный пример показывает преобразование с помощью трех различных стилей XSLT чтобы получить три различных представления этих данных в форматах HTML, SVG и VRML.

Входные данные:

<sales>

<division id='North'>

<revenue>10</revenue>

<growth>9</growth>

<bonus>7</bonus>

Добавить отзыв
ВСЕ ОТЗЫВЫ О КНИГЕ В ИЗБРАННОЕ

0

Вы можете отметить интересные вам фрагменты текста, которые будут доступны по уникальной ссылке в адресной строке браузера.

Отметить Добавить цитату
×