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

xpath part of the homework #8

Open
wants to merge 1 commit 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
18 changes: 18 additions & 0 deletions xpath.1.1.xsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8" ?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<h1>Выбрать людей, у которых есть телефон.</h1>
</body>
<xsl:apply-templates select="persons/person/phone"/>
</html>
</xsl:template>
<xsl:template match="persons/person/phone">
<p>
<xsl:value-of select="../login" />
</p>
</xsl:template>

</xsl:stylesheet>
18 changes: 18 additions & 0 deletions xpath.1.2.xsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8" ?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<h1>Выбрать людей, у которых есть мобильный телефон.</h1>
</body>
<xsl:apply-templates select="persons/person/phone[@type ='mobile']"/>
</html>
</xsl:template>
<xsl:template match="persons/person/phone[@type='mobile']">
<p>
<xsl:value-of select="../login" />
</p>
</xsl:template>

</xsl:stylesheet>
18 changes: 18 additions & 0 deletions xpath.1.3.xsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8" ?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<h1>Выбрать людей, у которых есть мобильный телефон.</h1>
</body>
<xsl:apply-templates select="persons/person[phone[@type='work'] and phone[@type='mobile']]" />
</html>
</xsl:template>
<xsl:template match="persons/person[phone[@type='work'] and phone[@type='mobile']]">
<p>
<xsl:value-of select="login" />
</p>
</xsl:template>

</xsl:stylesheet>
19 changes: 19 additions & 0 deletions xpath.1.4.xsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8" ?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<h1>Выбрать людей, у которых email начинается с `login@`.</h1>
</body>
<xsl:apply-templates select="persons/person/email[starts-with(., ../login)]" />
</html>
</xsl:template>

<xsl:template match="persons/person/email[starts-with(., ../login)]">
<p>
<xsl:value-of select="../login" />
</p>
</xsl:template>

</xsl:stylesheet>
18 changes: 18 additions & 0 deletions xpath.1.5.xsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8" ?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<h1>Выбрать людей, принадлежащих к группе html</h1>
</body>
<xsl:apply-templates select="persons/person/group[text() = 'html']"/>
</html>
</xsl:template>
<xsl:template match="persons/person/group[text() = 'html']">
<p>
<xsl:value-of select="../login" />
</p>
</xsl:template>

</xsl:stylesheet>
18 changes: 18 additions & 0 deletions xpath.1.6.xsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8" ?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<h1>Выбрать людей, у которых "длинный" логин (длиннее трех символов)</h1>
</body>
<xsl:apply-templates select="persons/person/login[string-length(text()) &gt; 3]"/>
</html>
</xsl:template>
<xsl:template match="persons/person/login[string-length(text()) &gt; 3]">
<p>
<xsl:value-of select="." />
</p>
</xsl:template>

</xsl:stylesheet>
22 changes: 22 additions & 0 deletions xpath.1.7.xsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8" ?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<h1>Выбрать для каждого человека по одному его контакту -
мобильный телефон, рабочий телефон или email (что-нибудь одно, все равно что).</h1>
</body>
<xsl:apply-templates select="persons/person[phone[@type='work'] or phone[@type='mobile'] or email]"/>
</html>
</xsl:template>
<xsl:template match="persons/person[phone[@type='work'] or phone[@type='mobile'] or email]">
<table>
<tr>
<td><xsl:value-of select="login" /></td>
<td><xsl:value-of select="email" /></td>
</tr>
</table>
</xsl:template>

</xsl:stylesheet>
39 changes: 39 additions & 0 deletions xpath.1.8.xsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?xml version="1.0" encoding="UTF-8" ?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<h1>Выбрать для каждого контакта его рабочий телефон, если нет рабочего, то мобильный,
если нет никакого телефона, то email.</h1>
<table>
<xsl:apply-templates select="persons/person[phone[@type='work'] or phone[@type='mobile'] or email]"/>
</table>
</body>


</html>
</xsl:template>
<xsl:template match="persons/person[phone[@type='work'] or phone[@type='mobile'] or email]">

<tr>
<td><xsl:value-of select="login" /></td>
<td>
<xsl:choose>
<xsl:when test="phone[@type='work']">
<xsl:value-of select="phone[@type='work']"/>
</xsl:when>
<xsl:when test="phone[@type='mobile']">
<xsl:value-of select="phone[@type='mobile']"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="email"/>
</xsl:otherwise>
</xsl:choose>

</td>
</tr>

</xsl:template>

</xsl:stylesheet>
19 changes: 19 additions & 0 deletions xpath.2.1.xsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8" ?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<h1>Выбрать все ноды, "глубина залегания" которых является четным числом
(для корневого элемента "глубина" равно 0.</h1>
</body>
<xsl:apply-templates select="items/*/* | items/*/*/*/*"/>
</html>
</xsl:template>
<xsl:template match="items/*/* | items/*/*/*/*">
<p>
<xsl:value-of select="@id" />
</p>
</xsl:template>

</xsl:stylesheet>
18 changes: 18 additions & 0 deletions xpath.2.2.xsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8" ?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<h1>Выбрать все ноды, у которых есть "старший брат" и "младший брат".</h1>
</body>
<xsl:apply-templates select="items//*[following-sibling::* and preceding-sibling::* ]"/>
</html>
</xsl:template>
<xsl:template match="items//*[following-sibling::* and preceding-sibling::* ]">
<p>
<xsl:value-of select="@id"/>
</p>
</xsl:template>

</xsl:stylesheet>
21 changes: 21 additions & 0 deletions xpath.2.3.xsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8" ?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<h1>Выбрать все ноды, у "деда" которых ровно 6 потомков.</h1>
</body>

<xsl:apply-templates select="items//*[count(descendant::*[parent::*/parent::*])=6]"/>
</html>
</xsl:template>


<xsl:template match="items//*[count(descendant::*[parent::*/parent::*])=6]">
<p>
<xsl:value-of select="@id" />
</p>
</xsl:template>

</xsl:stylesheet>
21 changes: 21 additions & 0 deletions xpath.2.4.xsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8" ?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<h1>Выбрать все ноды, у которых есть предок и потомок с одинаковым классом.</h1>
</body>

<xsl:apply-templates select="items//*[ancestor::*/@class=descendant::*/@class]"/>
</html>
</xsl:template>


<xsl:template match="items//*[ancestor::*/@class=descendant::*/@class]">
<p>
<xsl:value-of select="@id" />
</p>
</xsl:template>

</xsl:stylesheet>
27 changes: 27 additions & 0 deletions xpath.2.5.xsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8" ?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<h1>Вычислить максимальное и минимальное значение среди всех 'item' ов.</h1>
</body>
<xsl:for-each select="items//*[not(*)]">
<xsl:sort select="." data-type="number" order="descending"/>
<xsl:if test="position() = 1">
<p>Max: <xsl:value-of select="."/></p>

</xsl:if>
<xsl:if test="position() = last()">
<p>Min: <xsl:value-of select="."/></p>

</xsl:if>

</xsl:for-each>

</html>
</xsl:template>



</xsl:stylesheet>
19 changes: 19 additions & 0 deletions xpath.3.1.xsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8" ?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<h1>Выбрать `item`'ы, у которых `value` совпадает
с порядковым номером в списке, умноженным на 10.</h1>
</body>
<xsl:apply-templates select="items/item[value = position()*10]" />
</html>
</xsl:template>
<xsl:template match="items/item[value = position()*10]" >
<p>
<xsl:value-of select="@id" />
</p>
</xsl:template>

</xsl:stylesheet>
19 changes: 19 additions & 0 deletions xpath.3.2.xsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8" ?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<h1>Выбрать `item`'ы, у которых `value` больше, чем у
следующего за ним `item`'а.</h1>
</body>
<xsl:apply-templates select="items/item[value &gt; following-sibling::*[1]]" />
</html>
</xsl:template>
<xsl:template match="items/item[value &gt; following-sibling::*[1]]" >
<p>
<xsl:value-of select="@id" />
</p>
</xsl:template>

</xsl:stylesheet>
21 changes: 21 additions & 0 deletions xpath.3.4.xsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8" ?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<h1>Выбрать ноды, являющиеся и "хорошими", и "плохими".</h1>
<xsl:apply-templates select="items/item[contains(../bad, string(position())) and contains(../good, string(position()))]" />
</body>

</html>
</xsl:template>

<xsl:template match="items/item[contains(../bad, string(position())) and contains(../good, string(position()))]">

<p> <xsl:value-of select="@id" /></p>

</xsl:template>


</xsl:stylesheet>
24 changes: 24 additions & 0 deletions xpath.3.5.xsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8" ?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<h1>Выбрать все ноды, не связанные с "плохими" нодами.</h1>
<xsl:apply-templates select="items/item[not(contains(../bad, string(position())))]" />


</body>

</html>
</xsl:template>

<xsl:template match="items/item[not(contains(../bad, string(position())))]">

<p> <xsl:value-of select="@id" /></p>

</xsl:template>



</xsl:stylesheet>
Loading