<office code="ВТ">
<lesson no="2" complex="BT">
<?xml-stylesheet type='text/xsl' href='/time.xsl'?>
<timeTable>
<offices>
<office code="КУ">
<name>Курская</name>
<address>Костомаровский пер., дом 3, стр 4, Москва, 105120</address>
</office>
<office code="BT">
<name>ВДНХ Техноград</name>
<address>пр-т Мира, 119 строение 63, Москва, 129223</address>
</office>
</offices>
<lessons>
<lesson no="1" complex="КУ">
<thema>Обзор XML технологий</thema>
<date>2021-01-19</date>
<time>10:00</time>
</lesson>
<lesson no="2" complex="BT">
<thema>Введение в XML</thema>
<date>2021-01-23</date>
<time>17:20</time>
</lesson>
<lesson no="3" complex="BT">
<thema>Правила XML</thema>
<date>2021-01-26</date>
<time>15:30</time>
</lesson>
<lesson no="4" complex="КУ">
<thema>Пространства имён XML</thema>
<date>2021-01-29</date>
<time>10:00</time>
</lesson>
<lesson no="5" complex="BT">
<thema>DTD: Описание структуры документа</thema>
<date>2021-02-03</date>
<time>17:20</time>
</lesson>
<lesson no="6" complex="BT">
<thema>DTD: определение сущностей</thema>
<date>2021-02-08</date>
<time>15:30</time>
</lesson>
<lesson no="7" complex="КУ">
<thema>Введение в XML Схемы</thema>
<date>2021-02-12</date>
<time>10:00</time>
</lesson>
<lesson no="8" complex="BT">
<thema>XML Схема: типы данных</thema>
<date>2021-02-17</date>
<time>17:20</time>
</lesson>
<lesson no="9" complex="BT">
<thema>Атрибуты типов</thema>
<date>2021-02-21</date>
<time>15:30</time>
</lesson>
<lesson no="10" complex="КУ">
<thema>XML Схема: Расширение сложных типов</thema>
<date>2021-02-25</date>
<time>10:00</time>
</lesson>
</lessons>
</timeTable>
<xsl:stylesheet version="1.0" xmlns="http://www.w3.org/1999/xhtml" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<xsl:apply-templates select="timeTable"/>
</xsl:template>
<xsl:template match="timeTable">
<html>
<head>
<title>page</title>
</head>
<body>
<xsl:apply-templates select="offices"/>
</body>
</html>
</xsl:template>
<xsl:template match="offices">
<div>
<xsl:apply-templates select="office"/>
</div>
</xsl:template>
<xsl:template match="office">
<xsl:variable name="office_code" select="@code"/>
<div>
<xsl:text>Комплекс </xsl:text>
<xsl:value-of select="name"/>
<xsl:text>: всего занятий </xsl:text>
<xsl:value-of select="count(/timeTable/lessons/lesson[@complex = $office_code])"/>
<xsl:text>, занятий в 10:00 </xsl:text>
<xsl:value-of select="count(/timeTable/lessons/lesson[@complex = $office_code and time = '10:00'])"/>
</div>
</xsl:template>
</xsl:stylesheet>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>page</title>
</head>
<body>
<div>
<div>Комплекс Курская: всего занятий 4, занятий в 10:00 4</div>
<div>Комплекс ВДНХ Техноград: всего занятий 6, занятий в 10:00 0</div>
</div>
</body>
</html>
//div[not(contains(@style, 'none'))]
<root>
<foo>
<bar>
<baz>asdf</baz>
<text>text1</text>
</bar>
</foo>
<foo>
<bar>
<text>text2</text>
</bar>
</foo>
<foo>
<bar>
<baz>3</baz>
<text>text3</text>
</bar>
</foo>
</root>
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/root">
<xsl:apply-templates select="foo"/>
</xsl:template>
<xsl:template match="foo">
<h1 style="color:red;">
<xsl:attribute name="style">
<xsl:choose>
<xsl:when test="count(bar/baz) > 0">
<xsl:text>color: red;</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text>color: green;</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
<xsl:apply-templates select="bar/text"/>
</h1>
</xsl:template>
</xsl:stylesheet>
<h1 style="color: red;">text1</h1>
<h1 style="color: green;">text2</h1>
<h1 style="color: red;">text3</h1>
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/root/APPLICATION">
<html>
<body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;">
<h1><xsl:value-of select="root/APPLICATION/@NAME"/> </h1>
<table border="1">
<tr>
<td>ID</td>
<td>Deleted</td>
<td>IsLocked</td>
<td>RetriveTime</td>
<td>ChangeTime</td>
<td>AccessTime</td>
<td>SecureStyleID</td>
<td>Name</td>
<td>DBName</td>
<td>TheComment</td>
</tr>
<xsl:apply-templates select="MTZAPP_COL/MTZAPP | OBJECTMODE_COL/OBJECTMODE"/>
</table>
</body>
</html>
</xsl:template>
<xsl:template match="MTZAPP_COL/MTZAPP | OBJECTMODE_COL/OBJECTMODE">
<tr>
<td><xsl:value-of select="@ID"/></td>
<td><xsl:value-of select="@Deleted"/></td>
<td><xsl:value-of select="@IsLocked"/></td>
<td><xsl:value-of select="@RetriveTime"/></td>
<td><xsl:value-of select="@ChangeTime"/></td>
<td><xsl:value-of select="@AccessTime"/></td>
<td><xsl:value-of select="@SecureStyleID"/></td>
<td><xsl:value-of select="@Name"/></td>
<td><xsl:value-of select="@DBName"/></td>
<td><xsl:value-of select="@TheComment"/></td>
</tr>
</xsl:template>
</xsl:stylesheet>
<?xml version="1.0"?>
<root>
<foo/>
</root>
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/">
<operations>
<xsl:call-template name="operation">
<xsl:with-param name="counter" select="5"/>
</xsl:call-template>
</operations>
</xsl:template>
<xsl:template name="operation">
<xsl:param name="counter" select="1"/>
<operation>
<name>
<xsl:text>Ivan</xsl:text>
<xsl:value-of select="$counter"/>
</name>
<price>
<xsl:value-of select="100 * $counter"/>
</price>
</operation>
<xsl:if test="$counter > 0">
<xsl:call-template name="operation">
<xsl:with-param name="counter" select="$counter - 1"/>
</xsl:call-template>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
xsltproc proc.xsl data.xml > result.xml
cat result.xml
<?xml version="1.0"?>
<operations>
<operation>
<name>Ivan5</name>
<price>500</price>
</operation>
<operation>
<name>Ivan4</name>
<price>400</price>
</operation>
<operation>
<name>Ivan3</name>
<price>300</price>
</operation>
<operation>
<name>Ivan2</name>
<price>200</price>
</operation>
<operation>
<name>Ivan1</name>
<price>100</price>
</operation>
<operation>
<name>Ivan0</name>
<price>0</price>
</operation>
</operations>
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/">
<operations>
<xsl:for-each select="1 to 10">
<operation>
<name>
<xsl:text>Ivan</xsl:text>
<xsl:value-of select="position()"/>
</name>
<price>
<xsl:value-of select="100 * position()"/>
</price>
</operation>
</xsl:for-each>
</operations>
</xsl:template>
</xsl:stylesheet>
saxonb-xslt -s:data.xml -xsl:proc.xsl -o:result.xml
cat result.xml
<?xml version="1.0" encoding="UTF-8"?>
<operations>
<operation>
<name>Ivan1</name>
<price>100</price>
</operation>
<operation>
<name>Ivan2</name>
<price>200</price>
</operation>
<operation>
<name>Ivan3</name>
<price>300</price>
</operation>
<operation>
<name>Ivan4</name>
<price>400</price>
</operation>
<operation>
<name>Ivan5</name>
<price>500</price>
</operation>
<operation>
<name>Ivan6</name>
<price>600</price>
</operation>
<operation>
<name>Ivan7</name>
<price>700</price>
</operation>
<operation>
<name>Ivan8</name>
<price>800</price>
</operation>
<operation>
<name>Ivan9</name>
<price>900</price>
</operation>
<operation>
<name>Ivan10</name>
<price>1000</price>
</operation>
</operations
Вопрос, как мне правильно составить XSL шаблон чтобы я мог пробежаться по всем вложенным группам?
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="yes" encoding="utf-8" version="1.0"/>
<xsl:template match="/informationsystem">
<xsl:if test="count(informationsystem_group) > 0">
<ul>
<xsl:apply-templates select="//informationsystem_group"/>
</ul>
</xsl:if>
</xsl:template>
<xsl:template match="informationsystem_group">
<li>
<xsl:value-of select="name"/>
</li>
</xsl:template>
</xsl:stylesheet>
<ФИО Фамилия="Алексеев" Имя="Алексей" Отчество="Алексеевич"></ФИО>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:str="http://exslt.org/strings" extension-element-prefixes="str">
<xsl:template match="/">
<xsl:apply-templates select="ФИО/@Имя"/>
</xsl:template>
<xsl:template match="ФИО/@Имя">
<tr>
<xsl:for-each select="str:tokenize(string(.), '')">
<td>
<xsl:value-of select="." />
</td>
</xsl:for-each>
</tr>
</xsl:template>
</xsl:stylesheet>
<tr><td>А</td><td>л</td><td>е</td><td>к</td><td>с</td><td>е</td><td>й</td></tr>
<documentRecipientAddressData>
<street>Centroallee 1000
Einfahrt Parkhaus 7 an der "Alten Waltz" gegenüber Tryp Hotel ...</street>
<street>Centroallee
1000
Einfahrt
Parkhaus 7 an der
"Alten Waltz" gegenüber Tryp Hotel ...</street>
<street>Centroallee 1000 Einfahrt Parkhaus 7 an der "Alten Waltz" gegenüber Tryp Hotel ...</street>
</documentRecipientAddressData>
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="/documentRecipientAddressData/street">
<xsl:variable name="street">
<xsl:call-template name="replace-line-breaks">
<xsl:with-param name="text">
<xsl:call-template name="normalize-line-breaks">
<xsl:with-param name="text" select="."/>
</xsl:call-template>
</xsl:with-param>
</xsl:call-template>
</xsl:variable>
<xsl:value-of select="normalize-space($street)"/>
<xsl:text>
</xsl:text>
<xsl:variable name="street">
<xsl:call-template name="normalize-line-breaks">
<xsl:with-param name="text" select="."/>
</xsl:call-template>
</xsl:variable>
<xsl:value-of select="replace($street, '\n', ', ')"/>
<xsl:text>

</xsl:text>
</xsl:template>
<xsl:template name="replace-line-breaks">
<xsl:param name="text"/>
<xsl:choose>
<xsl:when test="not(contains($text, '
'))">
<xsl:value-of select="$text"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="substring-before($text, '
')"/>
<xsl:text>, </xsl:text>
<xsl:call-template name="replace-line-breaks">
<xsl:with-param name="text" select="substring-after($text, '
')"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="normalize-line-breaks">
<xsl:param name="text"/>
<xsl:choose>
<xsl:when test="not(contains($text, '

'))">
<xsl:value-of select="$text"/>
</xsl:when>
<xsl:otherwise>
<xsl:variable name="text">
<xsl:value-of select="substring-before($text, '

')"/>
<xsl:text>
</xsl:text>
<xsl:value-of select="substring-after($text, '

')"/>
</xsl:variable>
<xsl:call-template name="normalize-line-breaks">
<xsl:with-param name="text" select="$text"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
Centroallee 1000, Einfahrt Parkhaus 7 an der "Alten Waltz" gegenüber Tryp Hotel ...
Centroallee 1000, Einfahrt Parkhaus 7 an der "Alten Waltz" gegenüber Tryp Hotel ...
Centroallee, 1000, Einfahrt, Parkhaus 7 an der, "Alten Waltz" gegenüber Tryp Hotel ...
Centroallee, 1000, Einfahrt, Parkhaus 7 an der, "Alten Waltz" gegenüber Tryp Hotel ...
Centroallee 1000 Einfahrt Parkhaus 7 an der "Alten Waltz" gegenüber Tryp Hotel ...
Centroallee 1000 Einfahrt Parkhaus 7 an der "Alten Waltz" gegenüber Tryp Hotel ...
<root>
<div class="class1-s">a</div>
<div class="class1_a">b</div>
<div class=" class1+g ">b</div>
<div class="class1-s1">c</div>
<div class="class1-s134">c</div>
<div class="cls1-s134">c</div>
<div class="class1-s134">c</div>
<div c="zclass1-s1">c</div>
<div>c</div>
</root>
/root/div[starts-with(normalize-space(@class), 'class1') and string-length(normalize-space(@class)) = string-length('class1') + 2]
/root/div[matches(normalize-space(@class), '^class1..$')]
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/items">
<ul>
<xsl:apply-templates select="item[position() mod 2 = 1]" />
</ul>
</xsl:template>
<xsl:template match="item">
<li>
<img src="{@src}"/>
<img src="{following::item/@src}"/>
</li>
</xsl:template>
</xsl:stylesheet>
<ul>
<li>
<img src="/1.jpg"/>
<img src="/2.jpg"/>
</li>
<li>
<img src="/3.jpg"/>
<img src="/4.jpg"/>
</li>
<li>
<img src="/5.jpg"/>
<img src=""/>
</li>
</ul>