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

Xslt #31

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open

Xslt #31

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
66 changes: 66 additions & 0 deletions mephi.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="mephi.xsl"?>
<university name="МИФИ" city="Москва" metro="Каширская">
<faculty name="КиБ" dean="Евсеев">
<department tag="K" name="Информационные системы и технологии" number="36">
<group name="К5-361" number="1" amount="13" date="2012">
<student>Анисимова</student>
<student>Артемьев</student>
<student>Бубенко</student>
<student>Джелоухова</student>
<student>Заманов</student>
<student>Михеев</student>
<student>Пивоваров</student>
<student>Самсонов</student>
<student>Сидорова</student>
<student>Соловьёва</student>
<student>Тармазаков</student>
<student>Титоренко</student>
<student>Штанько</student>
</group>
<group name="К5-362" number="2" amount="17" date="2012">
<student>Ахметсафин</student>
<student>Галкин</student>
<student>Головко</student>
<student>Джумайло</student>
<student>Ерохин</student>
<student>Каталкина</student>
<student>Левин</student>
<student>Молочков</student>
<student>Моряшова</student>
<student>Полстянкин</student>
<student>Пурик</student>
<student>Разживин</student>
<student>Редюк</student>
<student>Рябов</student>
<student>Скок</student>
<student>Стрекалов</student>
<student>Чайковская</student>
</group>
</department>
<department tag="K" name="Программная инженерия" number="22">
<group name="К5-221" number="1" amount="1" date="2012">
<student>Седова</student>
</group>
</department>
<department tag="K" name="Математическое обеспечение систем" number="33">
<group name="К5-331" number="1" amount="1" date="2012">
<student>Хузин</student>
</group>
</department>
<department tag="K" name="Информационные технологии в социальных системах" number="68">
<group name="К5-682" number="2" amount="1" date="2012">
<student>Маляр</student>
</group>
</department>
</faculty>
<faculty name="Т">
<department tag="Т" name="Кафедра молекулярной физики" number="10">
<group name="Т3-101" number="1" amount="2" date="2013">
<student>Иванов</student>
<student>Петров</student>
<student>Сидоров</student>
</group>
</department>
</faculty>
</university>
8 changes: 8 additions & 0 deletions mephi1.xsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<xsl:for-each select="//faculty[@name='КиБ']/department">
<xsl:value-of select="@number"/>,
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
106 changes: 106 additions & 0 deletions mephi2.xsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">

<university name="МИФИ" city="Москва" metro="Каширская">

<faculty name="КиБ" dean="Евсеев">
<department tag="K" name="Информационные системы и технологии" number="36">
<group name="К5-361" number="1" amount="13" date="2012">
<xsl:attribute name="fullname">
<xsl:for-each select="//group[@name='К5-361']">
<xsl:value-of select="concat(string(ancestor::department/@tag),string(2*(2014.0-number(@date))+1),'-',string(ancestor::department/@number),string(@number))"/>
</xsl:for-each>
</xsl:attribute>

<student>Анисимова</student>
<student>Артемьев</student>
<student>Бубенко</student>
<student>Джелоухова</student>
<student>Заманов</student>
<student>Михеев</student>
<student>Пивоваров</student>
<student>Самсонов</student>
<student>Сидорова</student>
<student>Соловьёва</student>
<student>Тармазаков</student>
<student>Титоренко</student>
<student>Штанько</student>
</group>
<group name="К5-362" number="2" amount="17" date="2012">
<xsl:attribute name="fullname">
<xsl:for-each select="//group[@name='К5-362']">
<xsl:value-of select="concat(string(ancestor::department/@tag),string(2*(2014.0-number(@date))+1),'-',string(ancestor::department/@number),string(@number))"/>
</xsl:for-each>
</xsl:attribute>
<student>Ахметсафин</student>
<student>Галкин</student>
<student>Головко</student>
<student>Джумайло</student>
<student>Ерохин</student>
<student>Каталкина</student>
<student>Левин</student>
<student>Молочков</student>
<student>Моряшова</student>
<student>Полстянкин</student>
<student>Пурик</student>
<student>Разживин</student>
<student>Редюк</student>
<student>Рябов</student>
<student>Скок</student>
<student>Стрекалов</student>
<student>Чайковская</student>
</group>
</department>
<department tag="K" name="Программная инженерия" number="22">
<group name="К5-221" number="1" amount="1" date="2012">
<xsl:attribute name="fullname">
<xsl:for-each select="//group[@name='К5-221']">
<xsl:value-of select="concat(string(ancestor::department/@tag),string(2*(2014.0-number(@date))+1),'-',string(ancestor::department/@number),string(@number))"/>
</xsl:for-each>
</xsl:attribute>
<student>Седова</student>
</group>
</department>
<department tag="K" name="Математическое обеспечение систем" number="33">
<group name="К5-331" number="1" amount="1" date="2012">
<xsl:attribute name="fullname">
<xsl:for-each select="//group[@name='К5-331']">
<xsl:value-of select="concat(string(ancestor::department/@tag),string(2*(2014.0-number(@date))+1),'-',string(ancestor::department/@number),string(@number))"/>
</xsl:for-each>
</xsl:attribute>
<student>Хузин</student>
</group>
</department>
<department tag="K" name="Информационные технологии в социальных системах" number="68">
<group name="К5-682" number="2" amount="1" date="2012">
<xsl:attribute name="fullname">
<xsl:for-each select="//group[@name='К5-682']">
<xsl:value-of select="concat(string(ancestor::department/@tag),string(2*(2014.0-number(@date))+1),'-',string(ancestor::department/@number),string(@number))"/>
</xsl:for-each>
</xsl:attribute>
<student>Маляр</student>
</group>
</department>
</faculty>
<faculty name="Т">
<department tag="Т" name="Кафедра молекулярной физики" number="10">
<group name="Т3-101" number="1" amount="2" date="2013">
<xsl:attribute name="fullname">
<xsl:for-each select="//group[@name='Т3-101']">
<xsl:value-of select="concat(string(ancestor::department/@tag),string(2*(2014.0-number(@date))+1),'-',string(ancestor::department/@number),string(@number))"/>
</xsl:for-each>
</xsl:attribute>
<student>Иванов</student>
<student>Петров</student>
<student>Сидоров</student>
</group>
</department>
</faculty>

</university>

</xsl:template>
</xsl:stylesheet>

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

<xsl:template match="/">
<html xmlns="http://www.w3.org/1999/xhtml" lang="ru-RU" xml:lang="ru-RU">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title>Задание №3</title>
</head>
<body>
<h2>Все студенты факультета КиБ</h2>
<table border="1">
<tr bgcolor="#9acd32">
<th style="text-align:left">Номер</th>
<th style="text-align:left">Студент</th>
<th style="text-align:left">Группа</th>
</tr>
<xsl:for-each select="//student[ancestor::faculty/@name='КиБ']">
<tr>
<td><xsl:value-of select="position()"/></td>
<td><xsl:value-of select="self::student"/></td>
<td><xsl:value-of select="concat(string(ancestor::department/@tag),string(2*(2014.0-number(parent::group/@date))+1),'-',string(ancestor::department/@number),string(parent::group/@number))"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>


6 changes: 6 additions & 0 deletions task1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0"?>
36,
22,
33,
68,

2 changes: 2 additions & 0 deletions task2.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version="1.0"?>
<university name="&#x41C;&#x418;&#x424;&#x418;" city="&#x41C;&#x43E;&#x441;&#x43A;&#x432;&#x430;" metro="&#x41A;&#x430;&#x448;&#x438;&#x440;&#x441;&#x43A;&#x430;&#x44F;"><faculty name="&#x41A;&#x438;&#x411;" dean="&#x415;&#x432;&#x441;&#x435;&#x435;&#x432;"><department tag="K" name="&#x418;&#x43D;&#x444;&#x43E;&#x440;&#x43C;&#x430;&#x446;&#x438;&#x43E;&#x43D;&#x43D;&#x44B;&#x435; &#x441;&#x438;&#x441;&#x442;&#x435;&#x43C;&#x44B; &#x438; &#x442;&#x435;&#x445;&#x43D;&#x43E;&#x43B;&#x43E;&#x433;&#x438;&#x438;" number="36"><group name="&#x41A;5-361" number="1" amount="13" date="2012" fullname="K5-361"><student>Анисимова</student><student>Артемьев</student><student>Бубенко</student><student>Джелоухова</student><student>Заманов</student><student>Михеев</student><student>Пивоваров</student><student>Самсонов</student><student>Сидорова</student><student>Соловьёва</student><student>Тармазаков</student><student>Титоренко</student><student>Штанько</student></group><group name="&#x41A;5-362" number="2" amount="17" date="2012" fullname="K5-362"><student>Ахметсафин</student><student>Галкин</student><student>Головко</student><student>Джумайло</student><student>Ерохин</student><student>Каталкина</student><student>Левин</student><student>Молочков</student><student>Моряшова</student><student>Полстянкин</student><student>Пурик</student><student>Разживин</student><student>Редюк</student><student>Рябов</student><student>Скок</student><student>Стрекалов</student><student>Чайковская</student></group></department><department tag="K" name="&#x41F;&#x440;&#x43E;&#x433;&#x440;&#x430;&#x43C;&#x43C;&#x43D;&#x430;&#x44F; &#x438;&#x43D;&#x436;&#x435;&#x43D;&#x435;&#x440;&#x438;&#x44F;" number="22"><group name="&#x41A;5-221" number="1" amount="1" date="2012" fullname="K5-221"><student>Седова</student></group></department><department tag="K" name="&#x41C;&#x430;&#x442;&#x435;&#x43C;&#x430;&#x442;&#x438;&#x447;&#x435;&#x441;&#x43A;&#x43E;&#x435; &#x43E;&#x431;&#x435;&#x441;&#x43F;&#x435;&#x447;&#x435;&#x43D;&#x438;&#x435; &#x441;&#x438;&#x441;&#x442;&#x435;&#x43C;" number="33"><group name="&#x41A;5-331" number="1" amount="1" date="2012" fullname="K5-331"><student>Хузин</student></group></department><department tag="K" name="&#x418;&#x43D;&#x444;&#x43E;&#x440;&#x43C;&#x430;&#x446;&#x438;&#x43E;&#x43D;&#x43D;&#x44B;&#x435; &#x442;&#x435;&#x445;&#x43D;&#x43E;&#x43B;&#x43E;&#x433;&#x438;&#x438; &#x432; &#x441;&#x43E;&#x446;&#x438;&#x430;&#x43B;&#x44C;&#x43D;&#x44B;&#x445; &#x441;&#x438;&#x441;&#x442;&#x435;&#x43C;&#x430;&#x445;" number="68"><group name="&#x41A;5-682" number="2" amount="1" date="2012" fullname="K5-682"><student>Маляр</student></group></department></faculty><faculty name="&#x422;"><department tag="&#x422;" name="&#x41A;&#x430;&#x444;&#x435;&#x434;&#x440;&#x430; &#x43C;&#x43E;&#x43B;&#x435;&#x43A;&#x443;&#x43B;&#x44F;&#x440;&#x43D;&#x43E;&#x439; &#x444;&#x438;&#x437;&#x438;&#x43A;&#x438;" number="10"><group name="&#x422;3-101" number="1" amount="2" date="2013" fullname="&#x422;3-101"><student>Иванов</student><student>Петров</student><student>Сидоров</student></group></department></faculty></university>
2 changes: 2 additions & 0 deletions task3.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version="1.0"?>
<html xmlns="http://www.w3.org/1999/xhtml" lang="ru-RU" xml:lang="ru-RU"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/><title>Задание №3</title></head><body><h2>Все студенты факультета КиБ</h2><table border="1"><tr bgcolor="#9acd32"><th style="text-align:left">Номер</th><th style="text-align:left">Студент</th><th style="text-align:left">Группа</th></tr><tr><td>1</td><td>Анисимова</td><td>K5-361</td></tr><tr><td>2</td><td>Артемьев</td><td>K5-361</td></tr><tr><td>3</td><td>Бубенко</td><td>K5-361</td></tr><tr><td>4</td><td>Джелоухова</td><td>K5-361</td></tr><tr><td>5</td><td>Заманов</td><td>K5-361</td></tr><tr><td>6</td><td>Михеев</td><td>K5-361</td></tr><tr><td>7</td><td>Пивоваров</td><td>K5-361</td></tr><tr><td>8</td><td>Самсонов</td><td>K5-361</td></tr><tr><td>9</td><td>Сидорова</td><td>K5-361</td></tr><tr><td>10</td><td>Соловьёва</td><td>K5-361</td></tr><tr><td>11</td><td>Тармазаков</td><td>K5-361</td></tr><tr><td>12</td><td>Титоренко</td><td>K5-361</td></tr><tr><td>13</td><td>Штанько</td><td>K5-361</td></tr><tr><td>14</td><td>Ахметсафин</td><td>K5-362</td></tr><tr><td>15</td><td>Галкин</td><td>K5-362</td></tr><tr><td>16</td><td>Головко</td><td>K5-362</td></tr><tr><td>17</td><td>Джумайло</td><td>K5-362</td></tr><tr><td>18</td><td>Ерохин</td><td>K5-362</td></tr><tr><td>19</td><td>Каталкина</td><td>K5-362</td></tr><tr><td>20</td><td>Левин</td><td>K5-362</td></tr><tr><td>21</td><td>Молочков</td><td>K5-362</td></tr><tr><td>22</td><td>Моряшова</td><td>K5-362</td></tr><tr><td>23</td><td>Полстянкин</td><td>K5-362</td></tr><tr><td>24</td><td>Пурик</td><td>K5-362</td></tr><tr><td>25</td><td>Разживин</td><td>K5-362</td></tr><tr><td>26</td><td>Редюк</td><td>K5-362</td></tr><tr><td>27</td><td>Рябов</td><td>K5-362</td></tr><tr><td>28</td><td>Скок</td><td>K5-362</td></tr><tr><td>29</td><td>Стрекалов</td><td>K5-362</td></tr><tr><td>30</td><td>Чайковская</td><td>K5-362</td></tr><tr><td>31</td><td>Седова</td><td>K5-221</td></tr><tr><td>32</td><td>Хузин</td><td>K5-331</td></tr><tr><td>33</td><td>Маляр</td><td>K5-682</td></tr></table></body></html>
28 changes: 28 additions & 0 deletions xslt.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/python
#-*- coding: UTF-8 -*-
import optparse, libxml2, sys, libxslt

def transform(xml_file, xsl_file, out_file):
xml_doc = libxml2.parseFile(xml_file)
xsl_doc = libxml2.parseFile(xsl_file)
xsl = libxslt.parseStylesheetDoc(xsl_doc)
out_doc = xsl.applyStylesheet(xml_doc ,None)
print out_doc
xsl.saveResultToFilename(out_file, out_doc, 0)
xsl.freeStylesheet()
out_doc.freeDoc()
xml_doc.freeDoc()

def main(argv):
op = optparse.OptionParser(description = U"XSLT-преобразования", prog="xslt", version="0.1", usage=U"%prog")
op.add_option("-x", "--xml", dest="xml", help=U"XML документ", metavar="XML_FILE")
op.add_option("-s", "--xsl", dest="xsl", help=U"XSL документ", metavar="XSL_FILE")
op.add_option("-o", "--out", dest="out", help=U"Выходной документ", metavar="OUT_FILE")
options, arguments = op.parse_args()
if options.xml and options.xsl and options.out:
transform(options.xml, options.xsl, options.out)
else:
op.print_help()

if __name__=='__main__':
main(sys.argv)