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 #28

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

Xslt #28

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 xml/mephi#1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version="1.0"?>
department #12, department #22, department #36,
8 changes: 8 additions & 0 deletions xml/mephi#1.xsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">
<xsl:for-each select="//faculty[@name='K']/*">department #<xsl:value-of select="./attribute::number"/>, </xsl:for-each>
</xsl:template>
</xsl:stylesheet>

8 changes: 8 additions & 0 deletions xml/mephi.dtd
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<!ELEMENT mephi (faculty+)>
<!ELEMENT faculty (department+)>
<!ELEMENT department (group+)>
<!ELEMENT group (student+)>
<!ELEMENT student (#PCDATA)>
<!ATTLIST faculty name CDATA #REQUIRED>
<!ATTLIST department number CDATA #REQUIRED>
<!ATTLIST group grnum CDATA #REQUIRED>
129 changes: 129 additions & 0 deletions xml/mephi.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
<html><body>
<h2>Table of Students</h2>
<table border="1">
<tr bgcolor="#9acd32">
<th style="text-align:left">Student</th>
<th style="text-align:left">Group</th>
</tr>
<tr>
<td>Дмитрий Артемьев</td>
<td>K5-361</td>
</tr>
<tr>
<td>Наталья Анисимова</td>
<td>K5-361</td>
</tr>
<tr>
<td>Кирилл Бубенко</td>
<td>K5-361</td>
</tr>
<tr>
<td>Алена Джелоухова</td>
<td>K5-361</td>
</tr>
<tr>
<td>Айнур Заманов</td>
<td>K5-361</td>
</tr>
<tr>
<td>Денис Михеев</td>
<td>K5-361</td>
</tr>
<tr>
<td>Александр Пивоваров</td>
<td>K5-361</td>
</tr>
<tr>
<td>Артем Самсонов</td>
<td>K5-361</td>
</tr>
<tr>
<td>Аня Соловьева</td>
<td>K5-361</td>
</tr>
<tr>
<td>Любовь Суханова</td>
<td>K5-361</td>
</tr>
<tr>
<td>Евгений Тармазаков</td>
<td>K5-361</td>
</tr>
<tr>
<td>Алексей Титоренко</td>
<td>K5-361</td>
</tr>
<tr>
<td>Александр Штанько</td>
<td>K5-361</td>
</tr>
<tr>
<td>Владислав Ахметсафин</td>
<td>K5-362</td>
</tr>
<tr>
<td>Александр Галкин</td>
<td>K5-362</td>
</tr>
<tr>
<td>Ирина Головко</td>
<td>K5-362</td>
</tr>
<tr>
<td>Евгений Джумайло</td>
<td>K5-362</td>
</tr>
<tr>
<td>Владимир Ерохин</td>
<td>K5-362</td>
</tr>
<tr>
<td>Виктория Каталкина</td>
<td>K5-362</td>
</tr>
<tr>
<td>Андрей Левин</td>
<td>K5-362</td>
</tr>
<tr>
<td>Ярослав Молочков</td>
<td>K5-362</td>
</tr>
<tr>
<td>Виктория Моряшова</td>
<td>K5-362</td>
</tr>
<tr>
<td>Константин Полстянкин</td>
<td>K5-362</td>
</tr>
<tr>
<td>Яна Пурик</td>
<td>K5-362</td>
</tr>
<tr>
<td>Никита Разживин</td>
<td>K5-362</td>
</tr>
<tr>
<td>Сергей Редюк</td>
<td>K5-362</td>
</tr>
<tr>
<td>Петр Рябов</td>
<td>K5-362</td>
</tr>
<tr>
<td>Дарья Скок</td>
<td>K5-362</td>
</tr>
<tr>
<td>Олег Стрекалов</td>
<td>K5-362</td>
</tr>
<tr>
<td>Александра Чухненко</td>
<td>K5-362</td>
</tr>
</table>
</body></html>
41 changes: 41 additions & 0 deletions xml/mephi.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?xml version="1.0" encoding="UTF-8"?>
<mephi>
<faculty name="K">
<department number="36">
<group grnum="1">
<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 grnum="2">
<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>
</faculty>
</mephi>
71 changes: 71 additions & 0 deletions xml/mephi.xsd
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?xml version="1.0" encoding="UTF-8" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">

<xs:simpleType name="names">
<xs:restriction base="xs:string">
<xs:enumeration value="K"/>
<xs:enumeration value="A"/>
<xs:enumeration value="IS"/>
<xs:enumeration value="F"/>
<xs:enumeration value="T"/>
<xs:enumeration value="U"/>
</xs:restriction>
</xs:simpleType>

<xs:simpleType name="numbers">
<xs:restriction base="xs:integer">
<xs:minExclusive value="0"/>
<xs:maxExclusive value="40"/>
</xs:restriction>
</xs:simpleType>

<xs:simpleType name="grnums">
<xs:restriction base="xs:integer">
<xs:minInclusive value="1"/>
<xs:maxInclusive value="4"/>
</xs:restriction>
</xs:simpleType>

<xs:simpleType name="years">
<xs:restriction base="xs:integer">
<xs:pattern value="[0-9][0-9][0-9][0-9]"/>
</xs:restriction>
</xs:simpleType>

<xs:simpleType name="students">
<xs:restriction base="xs:string">
<xs:pattern value="([а-яА-Я ])*"/>
</xs:restriction>
</xs:simpleType>

<xs:complexType name="groups">
<xs:sequence>
<xs:element name="student" type="students" maxOccurs="40" minOccurs="1"/>
</xs:sequence>
<xs:attribute name="grnum" type="grnums" use="required"/>
<xs:attribute name="year" type="years" use="required"/>
</xs:complexType>

<xs:complexType name="departments">
<xs:sequence>
<xs:element name="group" type="groups" maxOccurs="4" minOccurs="1"/>
</xs:sequence>
<xs:attribute name="number" type="xs:integer" use="required"/>
</xs:complexType>

<xs:complexType name="faculties">
<xs:sequence>
<xs:element name="department" type="departments" maxOccurs="100" minOccurs="1"/>
</xs:sequence>
<xs:attribute name="name" type="names" use="required"/>
</xs:complexType>

<xs:complexType name="universities">
<xs:sequence>
<xs:element name="faculty" type="faculties" maxOccurs="6" minOccurs="1"/>
</xs:sequence>
</xs:complexType>

<xs:element name="mephi" type="universities"/>

</xs:schema>
24 changes: 24 additions & 0 deletions xml/mephi.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>
<h2>Table of Students</h2>
<table border="1">
<tr bgcolor="#9acd32">
<th style="text-align:left">Student</th>
<th style="text-align:left">Group</th>
</tr>
<xsl:for-each select="//student">
<tr>
<td><xsl:value-of select="concat(string(@firstname), ' ', string(@lastname))"/></td>
<td><xsl:value-of select="concat(string(ancestor::faculty/attribute::name), string(1+2*(2014.0-number(ancestor::group/attribute::year))), '-', string(ancestor::department/attribute::number), string(ancestor::group/attribute::grnum))"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>

43 changes: 43 additions & 0 deletions xml/mephi_i.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mephi SYSTEM "mephi.dtd">
<mephi xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="/home/serg/db36/xml/mephi.xsd">
<faculty name="K">
<department number="36">
<group grnum="1" year="2012">
<student firstname="Дмитрий" lastname="Артемьев"/>
<student firstname="Наталья" lastname="Анисимова"/>
<student firstname="Кирилл" lastname="Бубенко"/>
<student firstname="Алена" lastname="Джелоухова"/>
<student firstname="Айнур" lastname="Заманов"/>
<student firstname="Денис" lastname="Михеев"/>
<student firstname="Александр" lastname="Пивоваров"/>
<student firstname="Артем" lastname="Самсонов"/>
<student firstname="Аня" lastname="Соловьева"/>
<student firstname="Любовь" lastname="Суханова"/>
<student firstname="Евгений" lastname="Тармазаков"/>
<student firstname="Алексей" lastname="Титоренко"/>
<student firstname="Александр" lastname="Штанько"/>
</group>
<group grnum="2" year="2012">
<student firstname="Владислав" lastname="Ахметсафин"/>
<student firstname="Александр" lastname="Галкин"/>
<student firstname="Ирина" lastname="Головко"/>
<student firstname="Евгений" lastname="Джумайло"/>
<student firstname="Владимир" lastname="Ерохин"/>
<student firstname="Виктория" lastname="Каталкина"/>
<student firstname="Андрей" lastname="Левин"/>
<student firstname="Ярослав" lastname="Молочков"/>
<student firstname="Виктория" lastname="Моряшова"/>
<student firstname="Константин" lastname="Полстянкин"/>
<student firstname="Яна" lastname="Пурик"/>
<student firstname="Никита" lastname="Разживин"/>
<student firstname="Сергей" lastname="Редюк"/>
<student firstname="Петр" lastname="Рябов"/>
<student firstname="Дарья" lastname="Скок"/>
<student firstname="Олег" lastname="Стрекалов"/>
<student firstname="Александра" lastname="Чухненко"/>
</group>
</department>
</faculty>
</mephi>
57 changes: 57 additions & 0 deletions xml/parser.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#! /usr/bin/env python
#-*- coding: UTF-8 -*-
import sys, libxml2, optparse

def space(dep):
for i in range(0, dep):
sys.stdout.write(" ")

depth = 0
def view(node):
global depth
print
space(depth)
sys.stdout.write(node.name+" ")
if node.properties is not None:
for _property in node.properties:
if _property.type == "attribute":
#print _property.name
sys.stdout.write(_property.content+" ")
child = node.children
depth = depth+1
while child.next is not None:
if child.type == "element":
view(child)
child = child.next
depth = depth-1
sys.stdout.write(child.content)

def open(xml_file):
doc = libxml2.parseFile(xml_file)
root = doc.getRootElement()
#print root.name
#print root.content
view(root)
doc.freeDoc()

def validate(xml_file, dtd_file):
doc = libxml2.parseFile(xml_file)
dtd = libxml2.parseDTD(None, dtd_file)
ctxt = libxml2.newValidCtxt()
ret = doc.validateDtd(ctxt, dtd)
dtd.freeDtd()
doc.freeDoc()
return ret

def main(argv):
op = optparse.OptionParser(description = U"Проверка на соответствие DTD", prog="dtd", version="0.1", usage=U"%prog")
op.add_option("-x", "--xml", dest="xml", help=U"XML документ", metavar="XML_FILE")
op.add_option("-d", "--dtd", dest="dtd", help=U"DTD документ", metavar="DTD_FILE")
options, arguments = op.parse_args()
if options.xml and options.dtd:
open(options.xml)
validate(options.xml, options.dtd)
else: op.print_help()

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