Your SlideShare is downloading. ×
0
Знакомство с XSLT
Знакомство с XSLT
Знакомство с XSLT
Знакомство с XSLT
Знакомство с XSLT
Знакомство с XSLT
Знакомство с XSLT
Знакомство с XSLT
Знакомство с XSLT
Знакомство с XSLT
Знакомство с XSLT
Знакомство с XSLT
Знакомство с XSLT
Знакомство с XSLT
Знакомство с XSLT
Знакомство с XSLT
Знакомство с XSLT
Знакомство с XSLT
Знакомство с XSLT
Знакомство с XSLT
Знакомство с XSLT
Знакомство с XSLT
Знакомство с XSLT
Знакомство с XSLT
Знакомство с XSLT
Знакомство с XSLT
Знакомство с XSLT
Знакомство с XSLT
Знакомство с XSLT
Знакомство с XSLT
Знакомство с XSLT
Знакомство с XSLT
Знакомство с XSLT
Знакомство с XSLT
Знакомство с XSLT
Знакомство с XSLT
Знакомство с XSLT
Знакомство с XSLT
Знакомство с XSLT
Знакомство с XSLT
Знакомство с XSLT
Знакомство с XSLT
Знакомство с XSLT
Знакомство с XSLT
Знакомство с XSLT
Знакомство с XSLT
Знакомство с XSLT
Знакомство с XSLT
Знакомство с XSLT
Знакомство с XSLT
Знакомство с XSLT
Знакомство с XSLT
Знакомство с XSLT
Знакомство с XSLT
Знакомство с XSLT
Знакомство с XSLT
Знакомство с XSLT
Знакомство с XSLT
Знакомство с XSLT
Знакомство с XSLT
Знакомство с XSLT
Знакомство с XSLT
Знакомство с XSLT
Знакомство с XSLT
Знакомство с XSLT
Знакомство с XSLT
Знакомство с XSLT
Знакомство с XSLT
Знакомство с XSLT
Знакомство с XSLT
Знакомство с XSLT
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

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

1,228

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
1,228
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
13
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. XSLT
  • 2. XSLT is . . . XML XSLT XSL-FO XPath
  • 3. XSLT is . . . XML XSLT XSL-FO XPath
  • 4. Аналогия XML HTML ~ + + XSLT CSS
  • 5. Аналогия XML HTML ~ + + XSLT CSS XPath Selector
  • 6. Назначение XSLT XML XML
  • 7. Назначение XSLT XML HTML Сервер Браузер
  • 8. Назначение XSLT XML HTML Сервер Браузер
  • 9. Declaration <xsl:stylesheet 



version=quot;1.0quot; 



xmlns:xsl= 



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




XSL/Transformquot;> 
 



.
.
. 
 </xsl:stylesheet>
  • 10. Declaration <?xml
version=quot;1.0quot;?> <xsl:stylesheet 



version=quot;1.0quot; 



xmlns:xsl= 



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




XSL/Transformquot;> 
 



.
.
. 
 </xsl:stylesheet>
  • 11. Рабочий пример <?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>
  • 12. Рабочий пример <?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>
  • 13. Рабочий пример <?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>
  • 14. Рабочий пример. Вариант 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>
  • 15. Ожидаемый результат <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>
  • 16. 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>
  • 17. 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>
  • 18. 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>
  • 19. 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>
  • 20. 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>
  • 21. 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>
  • 22. 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>
  • 23. 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>
  • 24. 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>
  • 25. 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>
  • 26. 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>
  • 27. 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>
  • 28. 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>
  • 29. 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>
  • 30. 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>
  • 31. XSLT <xsl:template
match=quot;itemquot;> 



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







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



</a> 



.
.
. </xsl:template>
  • 32. 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>
  • 33. Рабочий пример. Вариант 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>
  • 34. Рабочий пример. Вариант 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>
  • 35. XSLT <xsl:template
match=quot;/pagequot;> 



<div> 







<xsl:apply‐templates 











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



</div> </xsl:template>
  • 36. 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>
  • 37. 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>
  • 38. Примеры 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]
  • 39. Оси 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
  • 40. Оси 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
  • 41. Арифметические операции в 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;/>
  • 42. Строковые функции в 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())
  • 43. Прочие функции в 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;
  • 44. Элементы 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; />
  • 45. Элементы 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>
  • 46. Последовательность обхода 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;/>
  • 47. Обработка узлов (создание дерева) <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>
  • 48. Обработка узлов <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>
  • 49. Обработка узлов <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>
  • 50. Обработка узлов <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>
  • 51. 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>
  • 52. 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>
  • 53. Шаблон с именем <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>
  • 54. Создание элементов <xsl:element
name=quot;bodyquot;> 



<xsl:copy‐of 







select=quot;/page/content/*
|
/page/content/text()quot;/> </xsl:element>
  • 55. Создание элементов и аттрибутов <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>
  • 56. Создание элементов и аттрибутов <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>

  • 57. Комментарии <!‐‐
xml
comment
‐‐> <xsl:text
disable‐output‐escaping=quot;yesquot;> 



<!‐‐
strange
comment
‐‐> </xsl:text> <xsl:comment> 


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


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


from=quot;sectionsquot; 


count=quot;itemquot; 


format=quot;Aquot;
|
quot;=1:2=quot; />
  • 59. Нумерация <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> .
.
.
  • 60. Условия <xsl:if
test=quot;@colour
=
‘white’quot;> 


<xsl:apply‐templates/> </xsl:if>
  • 61. Условия <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>
  • 62. Условия <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>
  • 63. Сортировка <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>
  • 64. Переменные <xsl:variable
name=quot;yearquot;
select=quot;2007quot;/> <xsl:value‐of
select=quot;$yearquot;/>
  • 65. Переменные <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>
  • 66. Переменные <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>
  • 67. Переменные <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>
  • 68. Переменные <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>
  • 69. Переменные <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>
  • 70. Ключи <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>
  • 71. Часть 2

×