Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Done homework #5

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions 01.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="xpath.1.xsl" version="1.0"?>
<persons>
<person>
<login>robot</login>
Expand Down
4 changes: 3 additions & 1 deletion 02.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="xpath.2.xsl" version="1.0"?>
<items>
<item id="1" class="a">
<item id="1.1" class="b">
Expand All @@ -20,6 +22,6 @@
</item>
</item>
<item id="3" class="b">
<itemd id="3.1" class="c">3</item>
<item id="3.1" class="c">3</item>
</item>
</items>
19 changes: 19 additions & 0 deletions 03.xml
Original file line number Diff line number Diff line change
@@ -1,19 +1,38 @@
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="xpath.3.xsl" version="1.0"?>
<items>
<good>1,3,4</good>
<bad>2,3,5</bad>
<item id="first">
<value>50</value>
<related>
<id>second</id>
<id>third</id>
<id>fourth</id>
</related>
</item>
<item id="second">
<value>20</value>
<related>
<id>first</id>
</related>
</item>
<item id="third">
<value>30</value>
<related>
<id>fourth</id>
</related>
</item>
<item id="fourth">
<value>10</value>
<related>
<id>first</id>
</related>
</item>
<item id="last">
<value>40</value>
<related>
<id>first</id>
</related>
</item>
</items>
14 changes: 14 additions & 0 deletions 05.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="xslt.2.xsl" version="1.0"?>
<?xml-stylesheet type="text/xsl" href="xslt.2.1.xsl" version="1.0"?>
<html>
<body>
<div class="head">Заголовок</div>
<div class="block">
<b class="my-class"><i>Я</i> написал такой код:</b>
<div class="code">
<b>html</b> это <i style="color:red">пыщ</i>-пыщ.
</div>
</div>
</body>
</html>
25 changes: 25 additions & 0 deletions 06.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="xslt.3.xsl" version="1.0"?>

<page name="catalog">
<menu>
<item name="index"/>
<item name="catalog"/>
<item name="about"/>
<item name="help"/>
</menu>
<links>
<link name="about" href="/about/">О проекте</link>
<link name="catalog" href="/catalog/">Каталог</link>
<link name="help" href="/help/">Помощь</link>
<link name="index" href="/">Главная</link>
<link name="setup" href="/settings/">Настройки</link>
</links>
<content>
<list>
<item><p>Тут какой-то <b>текст</b></p></item>
<item><p>И еще <b>текста</b> куча</p></item>
<item><p>И еще что-то написано</p></item>
</list>
</content>
</page>
6 changes: 6 additions & 0 deletions 07.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="xslt.4.xsl" version="1.0"?>

<page>

</page>
72 changes: 72 additions & 0 deletions xpath.1.xsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">
<html><body>
<h2>Выбрать людей, у которых есть телефон.</h2>
<xsl:call-template name="phone"/>

<h2>Выбрать людей, у которых есть мобильный телефон.</h2>
<xsl:call-template name="phone-mob"/>

<h2>Выбрать людей, у которых есть и рабочий, и мобильный телефон.</h2>
<xsl:call-template name="phone-mob-work"/>

<h2>Выбрать людей, у которых email начинается с `login@`</h2>
<xsl:call-template name="email-login"/>

<h2>Выбрать людей, принадлежащих к группе html</h2>
<xsl:call-template name="group-html"/>

<h2>Выбрать людей, у которых "длинный" логин (длиннее трех символов)</h2>
<xsl:call-template name="login-length"/>

<h2>Выбрать для каждого человека по одному его контакту -
мобильный телефон, рабочий телефон или email (что-нибудь одно, все равно что).</h2>
<xsl:call-template name="choose-contact"/>

<h2>Выбрать для каждого контакта его рабочий телефон, если нет рабочего, то мобильный,
если нет никакого телефона, то email.</h2>
<xsl:call-template name="choose-contact-filter"/>

</body></html>
</xsl:template>


<xsl:template name="phone">
<ul><xsl:apply-templates select="//phone/preceding-sibling::login"/></ul>
</xsl:template>

<xsl:template name="phone-mob">
<ul><xsl:apply-templates select="/persons/person/phone[@type = 'mobile']/preceding-sibling::login"/></ul>
</xsl:template>

<xsl:template name="phone-mob-work">
<ul><xsl:apply-templates select="/persons/person[child::phone[@type = 'work'] and child::phone[@type = 'mobile']]/login"/></ul>
</xsl:template>

<xsl:template name="email-login">
<ul><xsl:apply-templates select="/persons/person/email[starts-with(., preceding-sibling::login[text()])]/preceding-sibling::login"/></ul>
</xsl:template>

<xsl:template name="group-html">
<ul><xsl:apply-templates select="/persons/person/group[text() = 'html']/preceding-sibling::login"/></ul>
</xsl:template>

<xsl:template name="login-length">
<ul><xsl:apply-templates select="/persons/person/login[string-length(normalize-space(.)) &gt; 3]"/></ul>
</xsl:template>

<xsl:template name="choose-contact">
<ul><xsl:apply-templates select="(/persons/person/login|/persons/person/*[self::email or self::phone[@type = 'work'] or self::phone[@type = 'mobile']][1])"/></ul>
</xsl:template>

<xsl:template name="choose-contact-filter">
<ul><xsl:apply-templates select="(/persons/person/login|/persons/person/*[self::email or self::phone[@type = 'work'] or self::phone[@type = 'mobile']][last()])"/></ul>
</xsl:template>

<xsl:template match="/persons/person/login">
<li><xsl:value-of select="text()"/></li>
</xsl:template>


</xsl:stylesheet>
50 changes: 50 additions & 0 deletions xpath.2.xsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html><body>
<h2>Выбрать все ноды, "глубина залегания" которых является четным числом
(для корневого элемента "глубина" равно 0.</h2>
<xsl:call-template name="even"/>

<h2>Выбрать все ноды, у которых есть "старший брат" и "младший брат".</h2>
<xsl:call-template name="big-brother"/>

<h2>Выбрать все ноды, у "деда" которых ровно 6 потомков.</h2>
<xsl:call-template name="grandpa"/>

<h2>Выбрать все ноды, у которых есть предок и потомок с одинаковым классом.</h2>
<xsl:call-template name="dad-child"/>

<h2>Вычислить максимальное и минимальное значение среди всех `item`'ов.</h2>
<xsl:call-template name="max-min"/>

</body></html>
</xsl:template>


<xsl:template name="even">
<ul><xsl:apply-templates select="//*[position() mod 2 = 0]"/></ul>
</xsl:template>

<xsl:template name="big-brother">
<ul><xsl:apply-templates select="//*[preceding-sibling::item and following-sibling::item]"/></ul>
</xsl:template>

<xsl:template name="grandpa">
<ul><xsl:apply-templates select="//*[count(descendant::*)=6]"/></ul>
</xsl:template>

<xsl:template name="dad-child">
<ul><xsl:apply-templates select="//*[parent::*/@class = child::*/@class]"/></ul>
</xsl:template>

<xsl:template name="max-min">
<ul><xsl:apply-templates select="//item[last()][not (. &lt; //item)]/text()|//item[1][not (. &gt; //item)]/text()"/></ul>
</xsl:template>

<xsl:template match="item">
<li><xsl:value-of select="concat(@id, ' ', text())"/></li>
</xsl:template>



</xsl:stylesheet>
53 changes: 53 additions & 0 deletions xpath.3.xsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">
<html><body>
<h2>Выбрать `item`'ы, у которых `value` совпадает
с порядковым номером в списке, умноженным на 10.</h2>
<xsl:call-template name="val-num"/>

<h2>Выбрать `item`'ы, у которых `value` больше, чем у
следующего за ним `item`'а.</h2>
<xsl:call-template name="val-compare"/>

<h2>Выбрать все "хорошие" ноды.</h2>
<xsl:call-template name="good"/>

<h2>Выбрать ноды, являющиеся и "хорошими", и "плохими".</h2>
<!--<xsl:call-template name="equal"/>-->

<h2>Выбрать все ноды, не связанные с "плохими" нодами.</h2>
<xsl:call-template name="not-bad"/>

</body></html>
</xsl:template>


<xsl:template name="val-num">
<ul><xsl:apply-templates select="//item[position()*10 = number(child::value)]"/></ul>
</xsl:template>

<xsl:template name="val-compare">
<ul><xsl:apply-templates select="//item[child::value/text() &lt; following-sibling::item/child::value/text()]"/></ul>
</xsl:template>

<xsl:template name="good">
<ul><xsl:apply-templates select="//*[position() = number(substring(//good, 1, 1)) or position() = number(substring(//good, 3, 1)) or position() = number(substring(//good, 5, 1))]"/></ul>
</xsl:template>

<!--<xsl:template name="equal">-->
<!--<ul>-->
<!--<xsl:apply-templates select="//*[contains(//good, substring(//bad, 1, 1)) or contains(//good, substring(//bad, 3, 1)) or contains(//good, substring(//bad, 5, 1))]"/>-->
<!--</ul>-->
<!--</xsl:template>-->

<xsl:template name="not-bad">
<ul><xsl:apply-templates select="//*[position() != number(substring(//bad, 1, 1)) and position() != number(substring(//bad, 3, 1)) and position() != number(substring(//bad, 5, 1))]"/></ul>
</xsl:template>


<xsl:template match="//*">
<li><xsl:value-of select="concat(name(),' ', @id, ' ', text())"/></li>
</xsl:template>

</xsl:stylesheet>
9 changes: 9 additions & 0 deletions xslt.1.xsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">
<xsl:text>
11, 8, 6
</xsl:text>
</xsl:template>

</xsl:stylesheet>
9 changes: 9 additions & 0 deletions xslt.2.1.xsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="b|i">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>

</xsl:stylesheet>
45 changes: 45 additions & 0 deletions xslt.2.xsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="b">
<strong>
<xsl:apply-templates select="@*|node()"/>
</strong>
</xsl:template>

<xsl:template match="i">
<em>
<xsl:apply-templates select="@*|node()"/>
</em>
</xsl:template>


<xsl:template match="//div[@class = 'code']">
<pre>
<xsl:apply-templates select="@*|node()"/>
</pre>
</xsl:template>

<xsl:template match="//div[@class = 'head']">
<h1>
<xsl:apply-templates select="@*|node()"/>
</h1>
</xsl:template>


<xsl:template match="//@class|//@style"/>


<xsl:template match="//div[@class = 'code']//@*|//div[@class = 'code']//node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>


<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>

</xsl:stylesheet>
Loading