SlideShare una empresa de Scribd logo
1 de 71
Descargar para leer sin conexión
XSLT
XSLT is . . .

                XML
                XSLT
                XSL-FO
                XPath
XSLT is . . .

                XML
                XSLT
                XSL-FO
                XPath
Аналогия


     XML        HTML
            ~
      +           +
     XSLT        CSS
Аналогия


     XML        HTML
            ~
      +           +
     XSLT        CSS

    XPath       Selector
Назначение




             XSLT



     XML            XML
Назначение




             XSLT



     XML            HTML

  Сервер            Браузер
Назначение




             XSLT



     XML            HTML

  Сервер            Браузер
Declaration


<xsl:stylesheet




version=quot;1.0quot;




xmlns:xsl=




quot;http://www.w3.org/





XSL/Transformquot;>






.
.
.


</xsl:stylesheet>
Declaration

<?xml
version=quot;1.0quot;?>
<xsl:stylesheet




version=quot;1.0quot;




xmlns:xsl=




quot;http://www.w3.org/





XSL/Transformquot;>






.
.
.


</xsl:stylesheet>
Рабочий пример
<?xml
version=quot;1.0quot;?>
<page>




<sections>







<item
href=quot;politicsquot;>Политика</item>







<item
href=quot;worldquot;>В
мире</item>







<item
href=quot;economyquot;>Экономика</item>







<item
href=quot;societyquot;>Общество</item>




</sections>
</page>
Рабочий пример
<?xml
version=quot;1.0quot;?>
<page>




<sections>







<item
href=quot;politicsquot;>











<name>Политика</name>











<item
href=quot;russiaquot;>В
России</item>











<item
href=quot;foreignquot;>Внешняя...</item>











<item
href=quot;senatequot;>Совет...</item>







</item>







<item
href=quot;worldquot;>В
мире</item>







<item
href=quot;economyquot;>Экономика</item>







<item
href=quot;societyquot;>Общество</item>




</sections>
</page>
Рабочий пример
<?xml
version=quot;1.0quot;?>
<page>




<sections>







<item
href=quot;politicsquot;>











<name>Политика</name>











<item
href=quot;russiaquot;>















<name>В
России</name>











</item>











<item
href=quot;foreignquot;>















<name>Внешняя
политика</name>











</item>











<item
href=quot;senatequot;>















<name>Совет
Федерации</name>











</item>







</item>







.
.
.





</sections>
</page>
Рабочий пример. Вариант 1
<?xml
version=quot;1.0quot;?>
<page>




<sections>







<item
href=quot;politicsquot;
name=quot;Политикаquot;>











<item
href=quot;russiaquot;
name=quot;В
Россииquot;/>











<item
href=quot;foreignquot;
name=quot;Внешняя...quot;/>











<item
href=quot;senatequot;
name=quot;Совет...quot;/>







</item>







<item
href=quot;worldquot;
name=quot;В
миреquot;/>







<item
href=quot;economyquot;
name=quot;Экономикаquot;/>







<item
href=quot;societyquot;
name=quot;Обществоquot;/>




</sections>
</page>
Ожидаемый результат
<ul>



<li>






<a
href=quot;/politics/quot;>Политика</a>






<ul>









<li><a
href=quot;/politics/russia/quot;>В
России</a></li>









<li><a
href=quot;/politics/foreign/quot;>Внешняя...</a></li>









<li><a
href=quot;/politics/senate/quot;>В
России</a></li>






</ul>



</li>



<li>






<a
href=quot;/world/quot;>В
мире</a>



</li>



<li>






<a
href=quot;/society/quot;>Общество</a>



</li>
</ul>
XSLT
<?xml
version=quot;1.0quot;
encoding=quot;UTF‐8quot;?>
<xsl:stylesheet
version=quot;1.0quot;



xmlns:xsl=quot;http://www.w3.org/1999/XSL/Transformquot;>

<xsl:output




encoding=quot;UTF‐8quot;




indent=quot;yesquot;/>




</xsl:stylesheet>
XSLT
<?xml
version=quot;1.0quot;
encoding=quot;UTF‐8quot;?>
<xsl:stylesheet
version=quot;1.0quot;



xmlns:xsl=quot;http://www.w3.org/1999/XSL/Transformquot;>

<xsl:output




encoding=quot;UTF‐8quot;




indent=quot;yesquot;/>

<xsl:template
match=quot;/pagequot;>




<div>








<xsl:for‐each
select=quot;sections/itemquot;>












<a
href=quot;{@href}quot;>
















<xsl:value‐of
select=quot;@namequot;/>












</a>








</xsl:for‐each>




</div>
</xsl:template>

</xsl:stylesheet>
XSLT




<xsl:template
match=quot;/pagequot;>




<div>








<xsl:for‐each
select=quot;sections/itemquot;>












<a
href=quot;{@href}quot;>
















<xsl:value‐of
select=quot;@namequot;/>












</a>








</xsl:for‐each>




</div>
</xsl:template>
XSLT и XPath

                                     XPath



<xsl:template
match=quot;/pagequot;>




<div>








<xsl:for‐each
select=quot;sections/itemquot;>












<a
href=quot;{@href}quot;>
















<xsl:value‐of
select=quot;@namequot;/>












</a>








</xsl:for‐each>




</div>
</xsl:template>
XML + XSLT                 <page>
                           



<sections>
                           






<item
href=quot;politicsquot;
name=quot;Политикаquot;>
                           










<item
href=quot;russiaquot;
name=quot;В
Россииquot;/>
                           










<item
href=quot;foreignquot;
name=quot;Внешняя...quot;/>
                           










<item
href=quot;senatequot;
name=quot;Совет...quot;/>
                           






</item>
                           






<item
href=quot;worldquot;
name=quot;В
миреquot;/>
                           






<item
href=quot;economyquot;
name=quot;Экономикаquot;/>
                           






<item
href=quot;societyquot;
name=quot;Обществоquot;/>
                           



</sections>
                           </page>




<xsl:template
match=quot;/pagequot;>




<div>








<xsl:for‐each
select=quot;sections/itemquot;>












<a
href=quot;{@href}quot;>
















<xsl:value‐of
select=quot;@namequot;/>












</a>








</xsl:for‐each>




</div>
</xsl:template>
XML + XSLT                 <page>
                           



<sections>
                           






<item
href=quot;politicsquot;
name=quot;Политикаquot;>
                           










<item
href=quot;russiaquot;
name=quot;В
Россииquot;/>
                           










<item
href=quot;foreignquot;
name=quot;Внешняя...quot;/>
                           










<item
href=quot;senatequot;
name=quot;Совет...quot;/>
                           






</item>
                           






<item
href=quot;worldquot;
name=quot;В
миреquot;/>
                           






<item
href=quot;economyquot;
name=quot;Экономикаquot;/>
                           






<item
href=quot;societyquot;
name=quot;Обществоquot;/>
                           



</sections>
                           </page>




<xsl:template
match=quot;/pagequot;>




<div>








<xsl:for‐each
select=quot;sections/itemquot;>












<a
href=quot;{@href}quot;>
















<xsl:value‐of
select=quot;@namequot;/>












</a>








</xsl:for‐each>




</div>
</xsl:template>
XML + XSLT                 <page>
                           



<sections>
                           






<item
href=quot;politicsquot;
name=quot;Политикаquot;>
                           










<item
href=quot;russiaquot;
name=quot;В
Россииquot;/>
                           










<item
href=quot;foreignquot;
name=quot;Внешняя...quot;/>
                           










<item
href=quot;senatequot;
name=quot;Совет...quot;/>
                           






</item>
                           






<item
href=quot;worldquot;
name=quot;В
миреquot;/>
                           






<item
href=quot;economyquot;
name=quot;Экономикаquot;/>
                           






<item
href=quot;societyquot;
name=quot;Обществоquot;/>
                           



</sections>
                           </page>




<xsl:template
match=quot;/pagequot;>




<div>








<xsl:for‐each
select=quot;sections/itemquot;>












<a
href=quot;{@href}quot;>
















<xsl:value‐of
select=quot;@namequot;/>












</a>








</xsl:for‐each>




</div>
</xsl:template>
XML + XSLT                 <page>
                           



<sections>
                           






<item
href=quot;politicsquot;
name=quot;Политикаquot;>
                           










<item
href=quot;russiaquot;
name=quot;В
Россииquot;/>
                           










<item
href=quot;foreignquot;
name=quot;Внешняя...quot;/>
                           










<item
href=quot;senatequot;
name=quot;Совет...quot;/>
                           






</item>
                           






<item
href=quot;worldquot;
name=quot;В
миреquot;/>
                           






<item
href=quot;economyquot;
name=quot;Экономикаquot;/>
                           






<item
href=quot;societyquot;
name=quot;Обществоquot;/>
                           



</sections>
                           </page>




<xsl:template
match=quot;/pagequot;>




<div>








<xsl:for‐each
select=quot;sections/itemquot;>












<a
href=quot;{@href}quot;>
















<xsl:value‐of
select=quot;@namequot;/>












</a>








</xsl:for‐each>




</div>
</xsl:template>
XML + XSLT                 <page>
                           



<sections>
                           






<item
href=quot;politicsquot;
name=quot;Политикаquot;>
                           










<item
href=quot;russiaquot;
name=quot;В
Россииquot;/>
                           










<item
href=quot;foreignquot;
name=quot;Внешняя...quot;/>
                           










<item
href=quot;senatequot;
name=quot;Совет...quot;/>
                           






</item>
                           






<item
href=quot;worldquot;
name=quot;В
миреquot;/>
                           






<item
href=quot;economyquot;
name=quot;Экономикаquot;/>
                           






<item
href=quot;societyquot;
name=quot;Обществоquot;/>
                           



</sections>
                           </page>




<xsl:template
match=quot;/pagequot;>




<div>








<xsl:for‐each
select=quot;sections/itemquot;>












<a
href=quot;{@href}quot;>
















<xsl:value‐of
select=quot;@namequot;/>












</a>








</xsl:for‐each>




</div>
</xsl:template>
HTML
<?xml
version=quot;1.0quot;
encoding=quot;UTF‐8quot;?>
<div>


<a
href=quot;politicsquot;>Политика</a>


<a
href=quot;worldquot;>В
мире</a>


<a
href=quot;economyquot;>Экономика</a>


<a
href=quot;societyquot;>Общество</a>
</div>
XML + XSLT                 <page>
                           



<sections>
                           






<item
href=quot;politicsquot;
name=quot;Политикаquot;>
                           










<item
href=quot;russiaquot;
name=quot;В
Россииquot;/>
                           










<item
href=quot;foreignquot;
name=quot;Внешняя...quot;/>
                           










<item
href=quot;senatequot;
name=quot;Совет...quot;/>
                           






</item>
                           






<item
href=quot;worldquot;
name=quot;В
миреquot;/>
                           






<item
href=quot;economyquot;
name=quot;Экономикаquot;/>
                           






<item
href=quot;societyquot;
name=quot;Обществоquot;/>
                           



</sections>
                           </page>




<xsl:template
match=quot;/pagequot;>




<div>








<xsl:for‐each
select=quot;sections/itemquot;>












<a
href=quot;{@href}quot;>
















<xsl:value‐of
select=quot;@namequot;/>












</a>












?
<xsl:for‐each
select=quot;itemquot;>
?








</xsl:for‐each>




</div>
</xsl:template>
XSLT
<xsl:template
match=quot;/pagequot;>




<div>








<xsl:apply‐templates
select=quot;sections/itemquot;/>




</div>
</xsl:template>

<xsl:template
match=quot;itemquot;>




<a
href=quot;{@href}quot;>








<xsl:value‐of
select=quot;@namequot;/>




</a>




<xsl:if
test=quot;itemquot;>








<div>












<xsl:apply‐templates
select=quot;itemquot;/>








</div>




</xsl:if>
</xsl:template>
XML + XSLT
<xsl:template
match=quot;/pagequot;>




<div>








<xsl:apply‐templates
select=quot;sections/itemquot;/>




</div>
</xsl:template>

<xsl:template
match=quot;itemquot;>




<a
href=quot;{@href}quot;>








<xsl:value‐of
select=quot;@namequot;/>




</a>




<xsl:if
test=quot;itemquot;>








<div>












<xsl:apply‐templates
select=quot;itemquot;/>








</div>




</xsl:if>
</xsl:template>
XML + XSLT = HTML

<?xml
version=quot;1.0quot;
encoding=quot;UTF‐8quot;?>
<div>



<a
href=quot;politicsquot;>Политика</a>



<div>






<a
href=quot;russiaquot;>В
России</a>






<a
href=quot;foreignquot;>Внешняя
политика</a>






<a
href=quot;senatequot;>Совет
Федерации</a>



</div>



<a
href=quot;worldquot;>В
мире</a>



<a
href=quot;economyquot;>Экономика</a>



<a
href=quot;societyquot;>Общество</a>
</div>
XML + XSLT = HTML

<?xml
version=quot;1.0quot;
encoding=quot;UTF‐8quot;?>
<div>



<a
href=quot;/politics/quot;>Политика</a>



<div>






<a
href=quot;/politics/russia/quot;>В
России</a>






<a
href=quot;/politics/foreign/quot;>Внешняя
политика</a>






<a
href=quot;/politics/senate/quot;>Совет
Федерации</a>



</div>



<a
href=quot;/world/quot;>В
мире</a>



<a
href=quot;/economy/quot;>Экономика</a>



<a
href=quot;/society/quot;>Общество</a>
</div>
XSLT
<xsl:template
match=quot;itemquot;>




<a
href=quot;/{@href}/quot;>








<xsl:value‐of
select=quot;@namequot;/>




</a>




.
.
.
</xsl:template>
XSLT
<xsl:template
match=quot;itemquot;>




<a
href=quot;/{@href}/quot;>








<xsl:if
test=quot;parent::itemquot;>












<xsl:attribute
name=quot;hrefquot;>
















<xsl:text>/</xsl:text>
















<xsl:value‐of
select=quot;../item/@hrefquot;/>
















<xsl:text>/</xsl:text>
















<xsl:value‐of
select=quot;@hrefquot;/>
















<xsl:text>/</xsl:text>












</xsl:attribute>








</xsl:if>








<xsl:value‐of
select=quot;@namequot;/>




</a>




.
.
.
</xsl:template>
Рабочий пример. Вариант 2
<?xml
version=quot;1.0quot;?>
<page>




<sections>







<item
href=quot;politicsquot;
name=quot;Политикаquot;/>







<item
href=quot;worldquot;
name=quot;В
миреquot;/>







<item
href=quot;economyquot;
name=quot;Экономикаquot;/>







<item
href=quot;societyquot;
name=quot;Обществоquot;/>







<item
href=quot;russiaquot;
name=quot;В
Россииquot;













parent=quot;politicsquot;/>







<item
href=quot;foreignquot;
name=quot;Внешняя...quot;













parent=quot;politicsquot;/>







<item
href=quot;senatequot;
name=quot;Совет...quot;













parent=quot;politicsquot;/>




</sections>
</page>
Рабочий пример. Вариант 2
<?xml
version=quot;1.0quot;?>
<page>




<sections>







<item
href=quot;politicsquot;
name=quot;Политикаquot;/>







<item
href=quot;worldquot;
name=quot;В
миреquot;/>







<item
href=quot;economyquot;
name=quot;Экономикаquot;/>







<item
href=quot;societyquot;
name=quot;Обществоquot;/>







<item
href=quot;russiaquot;
name=quot;В
Россииquot;













parent=quot;politicsquot;/>







<item
href=quot;foreignquot;
name=quot;Внешняя...quot;













parent=quot;politicsquot;/>







<item
href=quot;senatequot;
name=quot;Совет...quot;













parent=quot;politicsquot;/>




</sections>
</page>
XSLT
<xsl:template
match=quot;/pagequot;>




<div>








<xsl:apply‐templates












select=quot;sections/item[not
(@parent)]quot;/>




</div>
</xsl:template>
XSLT
<xsl:template
match=quot;itemquot;>




<a
href=quot;/{@href}/quot;>








<xsl:if
test=quot;@parentquot;>












<xsl:attribute
name=quot;hrefquot;>
















<xsl:text>/</xsl:text>
















<xsl:value‐of
select=quot;@parentquot;/>
















<xsl:text>/</xsl:text>
















<xsl:value‐of
select=quot;@hrefquot;/>
















<xsl:text>/</xsl:text>












</xsl:attribute>








</xsl:if>








<xsl:value‐of
select=quot;@namequot;/>




</a>




<xsl:if
test=quot;../item[@parent
=
current()/@href]quot;>








<div>












<xsl:apply‐templates
















select=quot;../item[@parent
=
current()/@href]quot;/>








</div>




</xsl:if>
</xsl:template>
XSLT
<xsl:template
match=quot;itemquot;>




<a
href=quot;/{@parent}/{@href}/quot;>







<xsl:value‐of
select=quot;@namequot;/>




</a>




<xsl:if
test=quot;../item[@parent
=
current()/@href]quot;>








<div>












<xsl:apply‐templates
















select=quot;../item[@parent
=
current()/@href]quot;/>








</div>




</xsl:if>
</xsl:template>
Примеры XPath-выражений
a            a[last()]
*            a[position()
=
2]
a[1]         a[position()
=
last()]
a[b]
a[@c]        a[@title
=
quot;xxxquot;]
/a           a[count
(b)
=
3]
//a
a/b          a[@title
=
@title2
and
count
(b)
!=
0]
a//b         a[@title
=
@title2][count
(b)
!=
0]
.
..           a/*[name()
=
quot;unknownquot;]
./a          a/*/b[@name
or
@sirname]
@c
./@c         ../../../a[d]//b[not
(@title)]/text()
@*
*
|
text()   tr[position()
mod
2
=
1]
Оси XPath (axis)
self::b
parent::b
child::b


descendant::b
ancestor::b


descendant‐or‐self::b
ancestor‐or‐self::b


following‐sibling::b
preceding‐sibling::b


attribute::c
namespace::ns
Оси XPath (axis)
self::b                 .
parent::b               ../b
child::b                b


descendant::b           .//b
ancestor::b


descendant‐or‐self::b   .//b
|
.
ancestor‐or‐self::b


following‐sibling::b    ../*[position()
<

preceding‐sibling::b    current()/position()]


attribute::c            @c
namespace::ns
Арифметические операции в XPath
<xsl:value‐of
select=quot;3quot;/>
<xsl:value‐of
select=quot;1
+
2quot;/>


<xsl:value‐of
select=quot;@price
+
@taxquot;/>
<xsl:value‐of
select=quot;@salary
*
0.87quot;/>


<xsl:value‐of
select=quot;@visitors
div
365quot;/>
<xsl:value‐of
select=quot;@days
mod
7quot;/>
Строковые функции в XPath
string
(123)


concat
(quot;alphaquot;,
quot;betaquot;)
concat
(node/@attr,
quot;,
quot;,
@value)


starts‐with
(name(),
quot;itemquot;)
ends‐width


contains
(text(),
quot;Tiananmenquot;)


substring
(quot;20070102quot;,
5,
2)


substring‐before
(quot;2007‐01‐02quot;,
quot;‐quot;);
substring‐after
(quot;Aug
2007quot;,
quot;
quot;);


string‐length
(text())
Прочие функции в XPath
<item
value=quot;5quot;/>
<item
value=quot;2.3”/>
<item
value=
quot;‐9.3quot;/>


<xsl:value‐of
select=quot;sum
(item/@value)quot;/>


<xsl:value‐of
select=quot;number
(text())quot;/>


<xsl:value‐of
select=quot;floor
(@value)quot;/>
<xsl:value‐of
select=quot;ceiling
(@value)quot;/>
<xsl:value‐of
select=quot;round
(@value)quot;/>


<xsl:value‐of
select=quot;translate
(text(),






















‘abcdefghijklmnopqrstuvwxyz’,





















‘ABCDEFGHIJKLMNOPQRSTUVWXYZ’quot;
Элементы XSLT
<xsl:import
href=quot;another.xsltquot;/>
<xsl:include
href=quot;more.xsltquot;/>


<xsl:output



method=quot;htmlquot;
|
quot;xmlquot;
|
quot;textquot;
 
encoding=quot;KOI8‐Rquot;
 
indent=quot;yesquot;
|
quot;noquot;
/>
Элементы XSLT
<xsl:import
href=quot;another.xsltquot;/>
<xsl:include
href=quot;more.xsltquot;/>


<xsl:output



method=quot;htmlquot;
|
quot;xmlquot;
|
quot;textquot;
 
encoding=quot;KOI8‐Rquot;
 
indent=quot;yesquot;
|
quot;noquot;
/>



<xsl:template
match=quot;paraquot;>
</xsl:template>


<xsl:template
name=quot;template‐namequot;>
</xsl:template>
Последовательность обхода XSLT
<xsl:template
match=quot;/quot;>
</xsl:template>


<xsl:template
match=quot;/pagequot;>
</xsl:template>


<xsl:template
match=quot;/page/sectionsquot;>
</xsl:template>


<xsl:template
name=quot;sections/itemquot;>
</xsl:template>


<xsl:template
name=quot;itemquot;>
</xsl:template>


<xsl:template
match=quot;item[item]quot;/>
Обработка узлов (создание дерева)
<xsl:template
match=quot;/quot;>



<html>






<head>









<xsl:apply‐templates
select=quot;cssquot;/>









<xsl:apply‐templates
select=quot;jsquot;/>






</head>






<body>









<xsl:apply‐templates
select=quot;contentquot;/>






</body>



</html>
</xsl:template>
Обработка узлов
<xsl:template
match=quot;/quot;>



<html>






<head>









<xsl:apply‐templates
select=quot;cssquot;/>









<xsl:apply‐templates
select=quot;jsquot;/>






</head>






<body>









<xsl:apply‐templates
select=quot;contentquot;/>






</body>



</html>
</xsl:template>



<xsl:template
match=quot;pagequot;>



<xsl:apply‐templates
select=quot;.quot;/>
</xsl:template>
Обработка узлов
<css>



<item>default.css</item>



<item>weather.css</item>
</css>


<xsl:apply‐templates
select=quot;cssquot;/>



<xsl:template
match=quot;cssquot;>



<xsl:for‐each
select=quot;itemquot;>






<link









rel=quot;stylesheetquot;









type=quot;text/cssquot;









href=quot;text()quot;






/>



</xsl:for‐each>
</xsl:template>
Обработка узлов
<js>



<item>default.js</item>



<item>gwt.js</item>
</js>


<xsl:apply‐templates
select=quot;jsquot;/>



<xsl:template
match=quot;jsquot;>



<xsl:apply‐templates
select=quot;itemquot;/>
</xsl:template>


<xsl:template
match=quot;js/itemquot;>



<script
type=quot;text/javascriptquot;
src=quot;text()quot;>



</script>
</xsl:template>
mode
<xsl:template
match=quot;cssquot;
mode=quot;headerquot;>



<xsl:for‐each
select=quot;itemquot;>






<link
rel=quot;stylesheetquot;
type=quot;text/cssquot;









href=quot;{text()}quot;
/>



</xsl:for‐each>
</xsl:template>


<xsl:template
match=quot;cssquot;
mode=quot;debugquot;>



<ul>






<xsl:for‐each
select=quot;itemquot;>









<li>












<xsl:value‐of
select=quot;text()quot;/>









</li>






</xsl:for‐each>



</ul>
</xsl:template>
mode
<xsl:template
match=quot;/quot;>



<html>






<head>









<xsl:apply‐templates












select=quot;cssquot;












mode=quot;headerquot;









/>






</head>






<body>









<xsl:apply‐templates












select=quot;cssquot;












mode=quot;debugquot;









/>






</body>



</html>
</xsl:template>
Шаблон с именем
<xsl:template
name=quot;copywrightquot;>



<div
id=quot;Copywrightquot;>






<xsl:text>©
</xsl:text>






<xsl:value‐of
select=quot;/page/manifest/date/@year”/>



</div>
</xsl:template>



<xsl:template
match=quot;/quot;>



.
.
.




<body>







<xsl:apply‐templates
select=quot;contentquot;/>







<xsl:call‐template
name=quot;copywrightquot;/>




</body>



.
.
.
</xsl:template>
Создание элементов
<xsl:element
name=quot;bodyquot;>




<xsl:copy‐of








select=quot;/page/content/*
|
/page/content/text()quot;/>
</xsl:element>
Создание элементов и аттрибутов
<xsl:element
name=quot;bodyquot;>



<xsl:attribute
name=quot;stylequot;>







<xsl:text>background:
white</xsl:text>



</xsl:attribute>



<xsl:copy‐of






select=quot;/page/content/*
|
/page/content/text()quot;/>
</xsl:element>
Создание элементов и аттрибутов
<xsl:element
name=quot;bodyquot;>



<xsl:attribute
name=quot;stylequot;>







<xsl:text>background:
white</xsl:text>



</xsl:attribute>



<xsl:copy‐of






select=quot;/page/content/*
|
/page/content/text()quot;/>
</xsl:element>






























≈



<body
style=quot;background:
whitequot;>




<xsl:apply‐templates
select=quot;/page/contentquot;/>
</body>

Комментарии
<!‐‐
xml
comment
‐‐>



<xsl:text
disable‐output‐escaping=quot;yesquot;>




&lt;!‐‐
strange
comment
‐‐&gt;
</xsl:text>



<xsl:comment>



xslt
comment
</xsl:comment>
Нумерация
<xsl:number



level=quot;singlequot;
|
quot;multiplequot;
|
quot;anyquot;



from=quot;sectionsquot;



count=quot;itemquot;



format=quot;Aquot;
|
quot;=1:2=quot;
/>
Нумерация
<xsl:template
match=quot;itemquot;>



<xsl:number
format=quot;multiplequot;/>



<a
href=quot;{@href}quot;>






<xsl:value‐of
select=quot;{text()}quot;/>






</a>



.
.
.
</xsl:template>


<div>


1<a
href=quot;/politics/quot;>Политика</a>


<div>




1.1<a
href=quot;/russia/quot;>В
России</a>




1.2<a
href=quot;/foreign/quot;>Внешняя
политика</a>




1.3<a
href=quot;/senate/quot;>Совет
Федерации</a>


</div>
.
.
.
Условия
<xsl:if
test=quot;@colour
=
‘white’quot;>



<xsl:apply‐templates/>
</xsl:if>
Условия
<xsl:if
test=quot;@colour
=
‘white’quot;>



<xsl:apply‐templates/>
</xsl:if>


<xsl:choose>



<xsl:when
test=quot;@size
<
10quot;>






.
.
.



</xsl:when>



<xsl:when
test=quot;@size
=
10quot;>






.
.
.



</xsl:when>



<xsl:otherwise>






.
.
.



</xsl:otherwise>
</xsl:choose>
Условия
<xsl:if
test=quot;@colour
=
‘white’quot;>



<xsl:apply‐templates/>
</xsl:if>


<xsl:choose>



<xsl:when
test=quot;@size
<
10quot;>






.
.
.



</xsl:when>



<xsl:when
test=quot;@size
=
10quot;>






.
.
.



</xsl:when>



<xsl:otherwise>






.
.
.



</xsl:otherwise>
</xsl:choose>
Сортировка
<xsl:sort



select=quot;@hrefquot;



order=quot;ascendingquot;
|
quot;descendingquot;



case‐order=
quot;upper‐firstquot;
|
quot;lower‐firstquot;
/>



<xsl:for‐each
select=quot;itemquot;>



<xsl:sort
select=quot;text()quot;/>



<a
href=quot;{@href}quot;>






<xsl:value‐of
select=quot;text()quot;/>



</a>
</xsl:for‐each>
Переменные
<xsl:variable
name=quot;yearquot;
select=quot;2007quot;/>


<xsl:value‐of
select=quot;$yearquot;/>
Переменные
<xsl:variable
name=quot;yearquot;
select=quot;2007quot;/>


<xsl:value‐of
select=quot;$yearquot;/>


<xsl:variable
name=quot;copywrightquot;>



<p>






<xsl:value‐of
select=quot;$yearquot;/>



</p>



<ul>






<xsl:for‐each
select=quot;authors/itemquot;>









<li>












<xsl:value‐of
select=quot;@namequot;/>









</li>






</xsl:for‐each>



</ul>
</xsl:variable>
Переменные
<xsl:template
match=quot;itemquot;>



<xsl:param
name=quot;classquot;/>



<div
class=quot;$classquot;>






...



</div>
</xsl:template>


<xsl:apply‐templates
select=quot;itemquot;>



<xsl:with‐param
name=quot;classquot;
select=quot;’front’quot;/>
</xsl:apply‐templates>
Переменные
<xsl:template
match=quot;itemquot;>



<xsl:param
name=quot;classquot;/>



<div
class=quot;$classquot;>






...



</div>
</xsl:template>


<xsl:apply‐templates
select=quot;itemquot;>



<xsl:with‐param
name=quot;classquot;>front</xsl:with‐param>
</xsl:apply‐templates>
Переменные
<xsl:variable



name=quot;listquot;



select=quot;document
(‘site‐structure.xml’)quot;
/>



<xsl:template
name=quot;site‐menuquot;>



<xsl:for‐each
select=quot;$list/sections/itemquot;>






<a
href=quot;{@href}quot;>









<xsl:value‐of
select=quot;text()quot;/>






</a>



</xsl:for‐each>
</xsl:template>
Переменные
<xsl:variable



name=quot;listquot;



select=quot;document
(‘http://example.com/structure.xml’)quot;
/>



<xsl:template
name=quot;site‐menuquot;>



<xsl:for‐each
select=quot;$list/sections/itemquot;>






<a
href=quot;{@href}quot;>









<xsl:value‐of
select=quot;text()quot;/>






</a>



</xsl:for‐each>
</xsl:template>
Ключи
<xsl:key



name=quot;childrenquot;



match=quot;/page/sections/itemquot;



use=quot;@parentquot;/>





<xsl:template
match=quot;/page/sectionsquot;>




<xsl:for‐each
select=quot;item[not
(@parent)]quot;>








<a
href=quot;{@href}quot;>












<xsl:value‐of
select=quot;@namequot;/>








</a>








<xsl:for‐each
select=quot;key
('children',
@href)quot;>












<xsl:value‐of
select=quot;@namequot;/>












<xsl:if
test=quot;position()
!=
last()quot;>,
</xsl:if>








</xsl:for‐each>




</xsl:for‐each>
</xsl:template>
Часть 2

Más contenido relacionado

Destacado

Bicicleta Dacia
Bicicleta DaciaBicicleta Dacia
Bicicleta Daciaeinsteine
 
Frank L Loyd Wright
Frank L Loyd WrightFrank L Loyd Wright
Frank L Loyd WrightMuff
 
Artigo - Captação de recursos não reembolsáveis: dificuldades e limitações da...
Artigo - Captação de recursos não reembolsáveis: dificuldades e limitações da...Artigo - Captação de recursos não reembolsáveis: dificuldades e limitações da...
Artigo - Captação de recursos não reembolsáveis: dificuldades e limitações da...Mauricio Serafim
 
Economia criativa ou indústria criativa: Delimitação de um Conceito em Constr...
Economia criativa ou indústria criativa: Delimitação de um Conceito em Constr...Economia criativa ou indústria criativa: Delimitação de um Conceito em Constr...
Economia criativa ou indústria criativa: Delimitação de um Conceito em Constr...Mauricio Serafim
 
день матери
день материдень матери
день материFintfin
 
ApresentaçãO Sala Vip Altercom 2008
ApresentaçãO Sala Vip Altercom 2008ApresentaçãO Sala Vip Altercom 2008
ApresentaçãO Sala Vip Altercom 2008Ricardo Campos
 
25 juni 2008: ICT in het biologieonderwijs
25 juni 2008: ICT in het biologieonderwijs25 juni 2008: ICT in het biologieonderwijs
25 juni 2008: ICT in het biologieonderwijsElly Langewis
 
Potensi Strategi&Pendekatan Mengoptimum P&P
Potensi Strategi&Pendekatan Mengoptimum P&PPotensi Strategi&Pendekatan Mengoptimum P&P
Potensi Strategi&Pendekatan Mengoptimum P&Pprofmadyadrhjsuaidi
 
Thingsyoudon Tseeeveryday
Thingsyoudon TseeeverydayThingsyoudon Tseeeveryday
Thingsyoudon TseeeverydayNavalitorul
 
Задачи бизнеса и эволюция DLP: какова следующая ступень?
Задачи бизнеса и эволюция DLP: какова следующая ступень?Задачи бизнеса и эволюция DLP: какова следующая ступень?
Задачи бизнеса и эволюция DLP: какова следующая ступень?InfoWatch
 
Bodyart
BodyartBodyart
Bodyartalex
 

Destacado (18)

Educação
EducaçãoEducação
Educação
 
Bicicleta Dacia
Bicicleta DaciaBicicleta Dacia
Bicicleta Dacia
 
Toolwi.Com
Toolwi.ComToolwi.Com
Toolwi.Com
 
Frank L Loyd Wright
Frank L Loyd WrightFrank L Loyd Wright
Frank L Loyd Wright
 
Artigo - Captação de recursos não reembolsáveis: dificuldades e limitações da...
Artigo - Captação de recursos não reembolsáveis: dificuldades e limitações da...Artigo - Captação de recursos não reembolsáveis: dificuldades e limitações da...
Artigo - Captação de recursos não reembolsáveis: dificuldades e limitações da...
 
Guidelines for Assistant Referees
Guidelines for Assistant RefereesGuidelines for Assistant Referees
Guidelines for Assistant Referees
 
Economia criativa ou indústria criativa: Delimitação de um Conceito em Constr...
Economia criativa ou indústria criativa: Delimitação de um Conceito em Constr...Economia criativa ou indústria criativa: Delimitação de um Conceito em Constr...
Economia criativa ou indústria criativa: Delimitação de um Conceito em Constr...
 
Before Social Media
Before Social MediaBefore Social Media
Before Social Media
 
Ikea
IkeaIkea
Ikea
 
MíDia E Eu
MíDia E EuMíDia E Eu
MíDia E Eu
 
день матери
день материдень матери
день матери
 
ApresentaçãO Sala Vip Altercom 2008
ApresentaçãO Sala Vip Altercom 2008ApresentaçãO Sala Vip Altercom 2008
ApresentaçãO Sala Vip Altercom 2008
 
25 juni 2008: ICT in het biologieonderwijs
25 juni 2008: ICT in het biologieonderwijs25 juni 2008: ICT in het biologieonderwijs
25 juni 2008: ICT in het biologieonderwijs
 
Potensi Strategi&Pendekatan Mengoptimum P&P
Potensi Strategi&Pendekatan Mengoptimum P&PPotensi Strategi&Pendekatan Mengoptimum P&P
Potensi Strategi&Pendekatan Mengoptimum P&P
 
Thingsyoudon Tseeeveryday
Thingsyoudon TseeeverydayThingsyoudon Tseeeveryday
Thingsyoudon Tseeeveryday
 
Задачи бизнеса и эволюция DLP: какова следующая ступень?
Задачи бизнеса и эволюция DLP: какова следующая ступень?Задачи бизнеса и эволюция DLP: какова следующая ступень?
Задачи бизнеса и эволюция DLP: какова следующая ступень?
 
Formatos Da Web
Formatos Da WebFormatos Da Web
Formatos Da Web
 
Bodyart
BodyartBodyart
Bodyart
 

Más de Andrew Shitov

Creating a compiler in Perl 6
Creating a compiler in Perl 6Creating a compiler in Perl 6
Creating a compiler in Perl 6Andrew Shitov
 
Fun with Raspberry PI (and Perl)
Fun with Raspberry PI (and Perl)Fun with Raspberry PI (and Perl)
Fun with Raspberry PI (and Perl)Andrew Shitov
 
Параллельные вычисления в Perl 6
Параллельные вычисления в Perl 6Параллельные вычисления в Perl 6
Параллельные вычисления в Perl 6Andrew Shitov
 
Perl 6 for Concurrency and Parallel Computing
Perl 6 for Concurrency and Parallel ComputingPerl 6 for Concurrency and Parallel Computing
Perl 6 for Concurrency and Parallel ComputingAndrew Shitov
 
The Joy of Smartmatch
The Joy of SmartmatchThe Joy of Smartmatch
The Joy of SmartmatchAndrew Shitov
 
Perl 7, the story of
Perl 7, the story ofPerl 7, the story of
Perl 7, the story ofAndrew Shitov
 
Язык программирования Go для Perl-программистов
Язык программирования Go для Perl-программистовЯзык программирования Go для Perl-программистов
Язык программирования Go для Perl-программистовAndrew Shitov
 
Как очистить массив
Как очистить массивКак очистить массив
Как очистить массивAndrew Shitov
 
What's new in Perl 5.14
What's new in Perl 5.14What's new in Perl 5.14
What's new in Perl 5.14Andrew Shitov
 
Что нового в Perl 5.14
Что нового в Perl 5.14Что нового в Perl 5.14
Что нового в Perl 5.14Andrew Shitov
 
Text in search queries with examples in Perl 6
Text in search queries with examples in Perl 6Text in search queries with examples in Perl 6
Text in search queries with examples in Perl 6Andrew Shitov
 
There's more than one way to empty it
There's more than one way to empty itThere's more than one way to empty it
There's more than one way to empty itAndrew Shitov
 
How to clean an array
How to clean an arrayHow to clean an array
How to clean an arrayAndrew Shitov
 

Más de Andrew Shitov (20)

Perl6 one-liners
Perl6 one-linersPerl6 one-liners
Perl6 one-liners
 
Creating a compiler in Perl 6
Creating a compiler in Perl 6Creating a compiler in Perl 6
Creating a compiler in Perl 6
 
Fun with Raspberry PI (and Perl)
Fun with Raspberry PI (and Perl)Fun with Raspberry PI (and Perl)
Fun with Raspberry PI (and Perl)
 
Perl6 in-production
Perl6 in-productionPerl6 in-production
Perl6 in-production
 
Параллельные вычисления в Perl 6
Параллельные вычисления в Perl 6Параллельные вычисления в Perl 6
Параллельные вычисления в Perl 6
 
AllPerlBooks.com
AllPerlBooks.comAllPerlBooks.com
AllPerlBooks.com
 
Perl 6 for Concurrency and Parallel Computing
Perl 6 for Concurrency and Parallel ComputingPerl 6 for Concurrency and Parallel Computing
Perl 6 for Concurrency and Parallel Computing
 
The Joy of Smartmatch
The Joy of SmartmatchThe Joy of Smartmatch
The Joy of Smartmatch
 
YAPC::Europe 2013
YAPC::Europe 2013YAPC::Europe 2013
YAPC::Europe 2013
 
Perl 7, the story of
Perl 7, the story ofPerl 7, the story of
Perl 7, the story of
 
Язык программирования Go для Perl-программистов
Язык программирования Go для Perl-программистовЯзык программирования Go для Perl-программистов
Язык программирования Go для Perl-программистов
 
Как очистить массив
Как очистить массивКак очистить массив
Как очистить массив
 
What's new in Perl 5.14
What's new in Perl 5.14What's new in Perl 5.14
What's new in Perl 5.14
 
Что нового в Perl 5.14
Что нового в Perl 5.14Что нового в Perl 5.14
Что нового в Perl 5.14
 
Perl6 grammars
Perl6 grammarsPerl6 grammars
Perl6 grammars
 
Text in search queries with examples in Perl 6
Text in search queries with examples in Perl 6Text in search queries with examples in Perl 6
Text in search queries with examples in Perl 6
 
There's more than one way to empty it
There's more than one way to empty itThere's more than one way to empty it
There's more than one way to empty it
 
Perl 6 by example
Perl 6 by examplePerl 6 by example
Perl 6 by example
 
How to clean an array
How to clean an arrayHow to clean an array
How to clean an array
 
Perl 5.10 и 5.12
Perl 5.10 и 5.12Perl 5.10 и 5.12
Perl 5.10 и 5.12
 

Знакомство с XSLT