From bb09be50b8db571479f051ad075b82aebfcf59cb Mon Sep 17 00:00:00 2001 From: Nikolay Ivanov Date: Tue, 8 Sep 2015 20:42:45 +0300 Subject: [PATCH 1/7] mephi.xml --- NVIvanov/mephi.py | 37 +++++++++++++++++++++++++++++++++++++ NVIvanov/mephi.xml | 13 +++++++++++++ 2 files changed, 50 insertions(+) create mode 100755 NVIvanov/mephi.py create mode 100755 NVIvanov/mephi.xml diff --git a/NVIvanov/mephi.py b/NVIvanov/mephi.py new file mode 100755 index 0000000..04f4f15 --- /dev/null +++ b/NVIvanov/mephi.py @@ -0,0 +1,37 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +import sys +import libxml2 + + +def get_property_by_name(node, name): + for node_property in node.properties: + if node_property.type == 'attribute' and node_property.name == name: + return node_property.content + + +def main(argv): + if len(argv) != 2: + sys.stderr.write("Usage : %s xml_file" % (argv[0],)) + else: + doc = libxml2.parseFile(argv[1]) + university = doc.getRootElement() + print(get_property_by_name(university, "name")) + department = university.children.next.next.next.children.next.next.next + while department is not None: + if department.type == 'element': + print(" Кафедра №" + get_property_by_name(department, "number")) + group = department.children.next.next.next + while group is not None: + if group.type == 'element': + print(" " + get_property_by_name(group, "name")) + for student in group.children: + if student.type == 'element': + print(" %s) " % get_property_by_name(student, "number") + + get_property_by_name(student, "name")) + group = group.next + department = department.next + + +if __name__ == '__main__': + main(sys.argv) diff --git a/NVIvanov/mephi.xml b/NVIvanov/mephi.xml new file mode 100755 index 0000000..64c11bb --- /dev/null +++ b/NVIvanov/mephi.xml @@ -0,0 +1,13 @@ + + + Национальный исследовательский ядерный университет "МИФИ" + + Факультет кибернетики и информационной безопасности + + Информационные системы и технологии + + + + + + From d4b2d709d76412e76292c0559b85eb6eb91dc8ed Mon Sep 17 00:00:00 2001 From: Nikolay Ivanov Date: Tue, 15 Sep 2015 17:20:55 +0300 Subject: [PATCH 2/7] =?UTF-8?q?=D0=9E=D0=BF=D1=80=D0=B5=D0=B4=D0=B5=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D1=82=D0=B8=D0=BF=D0=B0=20=D0=B4?= =?UTF-8?q?=D0=BE=D0=BA=D1=83=D0=BC=D0=B5=D0=BD=D1=82=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- NVIvanov/mephi.dtd | 15 ++++++++++ NVIvanov/mephi.py | 71 +++++++++++++++++++++++++++++++++------------- NVIvanov/mephi.xml | 23 +++++++-------- 3 files changed, 78 insertions(+), 31 deletions(-) create mode 100644 NVIvanov/mephi.dtd diff --git a/NVIvanov/mephi.dtd b/NVIvanov/mephi.dtd new file mode 100644 index 0000000..66d0a7f --- /dev/null +++ b/NVIvanov/mephi.dtd @@ -0,0 +1,15 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/NVIvanov/mephi.py b/NVIvanov/mephi.py index 04f4f15..434cc08 100755 --- a/NVIvanov/mephi.py +++ b/NVIvanov/mephi.py @@ -2,6 +2,7 @@ # -*- coding: utf-8 -*- import sys import libxml2 +import optparse def get_property_by_name(node, name): @@ -10,27 +11,59 @@ def get_property_by_name(node, name): return node_property.content +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 parse_xml(xml_file): + doc = libxml2.parseFile(xml_file) + mephi = doc.getRootElement() + faculty = mephi.children + while faculty is not None: + if faculty.type == "element": + print(get_property_by_name(faculty, "name")) + department = faculty.children + while department is not None: + if department.type == "element": + print(" " + get_property_by_name(department, "name") + "(" + get_property_by_name(department, + "number") + ")") + group = department.children + while group is not None: + if group.type == "element": + print(" " + get_property_by_name(group, "name")) + student = group.children + while student is not None: + if student.type == "element": + print(" " + get_property_by_name(student, "name")) + student = student.next + group = group.next + department = department.next + faculty = faculty.next + doc.freeDoc() + + +def get_option_parser(): + 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") + return op + + def main(argv): - if len(argv) != 2: - sys.stderr.write("Usage : %s xml_file" % (argv[0],)) + op = get_option_parser() + options, arguments = op.parse_args() + if options.xml and options.dtd: + validate(options.xml, options.dtd) + parse_xml(options.xml) else: - doc = libxml2.parseFile(argv[1]) - university = doc.getRootElement() - print(get_property_by_name(university, "name")) - department = university.children.next.next.next.children.next.next.next - while department is not None: - if department.type == 'element': - print(" Кафедра №" + get_property_by_name(department, "number")) - group = department.children.next.next.next - while group is not None: - if group.type == 'element': - print(" " + get_property_by_name(group, "name")) - for student in group.children: - if student.type == 'element': - print(" %s) " % get_property_by_name(student, "number") + - get_property_by_name(student, "name")) - group = group.next - department = department.next + op.print_help() if __name__ == '__main__': diff --git a/NVIvanov/mephi.xml b/NVIvanov/mephi.xml index 64c11bb..4843f00 100755 --- a/NVIvanov/mephi.xml +++ b/NVIvanov/mephi.xml @@ -1,13 +1,12 @@ - - Национальный исследовательский ядерный университет "МИФИ" - - Факультет кибернетики и информационной безопасности - - Информационные системы и технологии - - - - - - + + + + + + + + + + \ No newline at end of file From 79ffa3b29a9e7a75d041e670205062b5729a353f Mon Sep 17 00:00:00 2001 From: Nikolay Ivanov Date: Tue, 22 Sep 2015 16:52:44 +0300 Subject: [PATCH 3/7] xml scheme --- NVIvanov/mephi.py | 57 ++++++++++++++++++++++------------- NVIvanov/mephi.xml | 26 ++++++++-------- NVIvanov/mephi.xsd | 75 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 125 insertions(+), 33 deletions(-) create mode 100644 NVIvanov/mephi.xsd diff --git a/NVIvanov/mephi.py b/NVIvanov/mephi.py index 434cc08..ee346db 100755 --- a/NVIvanov/mephi.py +++ b/NVIvanov/mephi.py @@ -11,14 +11,16 @@ def get_property_by_name(node, name): return node_property.content -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 validate(xml_file, xsd_file): + ctxt = libxml2.schemaNewParserCtxt(xsd_file) + schema = ctxt.schemaParse() + validationCtxt = schema.schemaNewValidCtxt() + res = validationCtxt.schemaValidateFile(xml_file, 0) + if res != 0: + print("VALIDATION_ERROR") + else: + print("VALIDATED") + parse_xml(xml_file) def parse_xml(xml_file): @@ -27,20 +29,34 @@ def parse_xml(xml_file): faculty = mephi.children while faculty is not None: if faculty.type == "element": - print(get_property_by_name(faculty, "name")) + title = faculty.children + while title is not None: + if title.type == "element": + print(title.content) + break + title = title.next department = faculty.children while department is not None: - if department.type == "element": - print(" " + get_property_by_name(department, "name") + "(" + get_property_by_name(department, - "number") + ")") + if department.type == "element" and (department.name == "department" or department.name == "кафедра"): + number = department.children + while number is not None: + if number.type == "element": + print(number.content) + break + number = number.next group = department.children while group is not None: - if group.type == "element": - print(" " + get_property_by_name(group, "name")) + if group.type == "element" and (group.name == "group" or group.name == "группа"): + title = group.children + while title is not None: + if title.type == "element": + print(title.content) + break + title = title.next student = group.children while student is not None: - if student.type == "element": - print(" " + get_property_by_name(student, "name")) + if student.type == "element" and (student.name == "student" or student.name == "студент"): + print(get_property_by_name(student, "name")) student = student.next group = group.next department = department.next @@ -49,19 +65,18 @@ def parse_xml(xml_file): def get_option_parser(): - op = optparse.OptionParser(description=U"Проверка на соответствие DTD", + op = optparse.OptionParser(description=U"Проверка на соответствие XSD", 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") + op.add_option("-d", "--xsd", dest="xsd", help=U"XSD документ", metavar="XSD_FILE") return op def main(argv): op = get_option_parser() options, arguments = op.parse_args() - if options.xml and options.dtd: - validate(options.xml, options.dtd) - parse_xml(options.xml) + if options.xml and options.xsd: + validate(options.xml, options.xsd) else: op.print_help() diff --git a/NVIvanov/mephi.xml b/NVIvanov/mephi.xml index 4843f00..bbb4185 100755 --- a/NVIvanov/mephi.xml +++ b/NVIvanov/mephi.xml @@ -1,12 +1,14 @@ - - - - - - - - - - - \ No newline at end of file + +<МИФИ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:noNamespaceSchemaLocation="mephi.xsd"> + <факультет> + <название>K + <кафедра> + <номер>36 + <группа> + <название>K05-361 + <студент name="Николай Иванов" born="1996" nomer_zachotkee="321205"/> + + + + \ No newline at end of file diff --git a/NVIvanov/mephi.xsd b/NVIvanov/mephi.xsd new file mode 100644 index 0000000..7123e78 --- /dev/null +++ b/NVIvanov/mephi.xsd @@ -0,0 +1,75 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file From fdf24ded697d2a29120db418655286a5c204aae7 Mon Sep 17 00:00:00 2001 From: Nikolay Ivanov Date: Tue, 13 Oct 2015 18:49:56 +0300 Subject: [PATCH 4/7] xpath --- NVIvanov/mephi.py | 16 ++++++++++++++-- NVIvanov/mephi.xml | 4 +++- NVIvanov/mephi.xsd | 2 ++ 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/NVIvanov/mephi.py b/NVIvanov/mephi.py index ee346db..8ddb4ef 100755 --- a/NVIvanov/mephi.py +++ b/NVIvanov/mephi.py @@ -1,10 +1,10 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- + import sys import libxml2 import optparse - def get_property_by_name(node, name): for node_property in node.properties: if node_property.type == 'attribute' and node_property.name == name: @@ -72,11 +72,23 @@ def get_option_parser(): return op +def xpath(xml_file, str1): + doc = libxml2.parseFile(xml_file) + ctxt = doc.xpathNewContext() + result = ctxt.xpathEval(str1) + for item in result: + print(item.content) + print + ctxt.xpathFreeContext() + doc.freeDoc() + + def main(argv): op = get_option_parser() options, arguments = op.parse_args() if options.xml and options.xsd: - validate(options.xml, options.xsd) + xpath(options.xml, "/МИФИ/факультет/кафедра/title") + xpath(options.xml, "/МИФИ/факультет/каферда/группа/student[1]") else: op.print_help() diff --git a/NVIvanov/mephi.xml b/NVIvanov/mephi.xml index bbb4185..3ee8c1a 100755 --- a/NVIvanov/mephi.xml +++ b/NVIvanov/mephi.xml @@ -4,10 +4,12 @@ <факультет> <название>K <кафедра> + Информационные системы и технологии <номер>36 <группа> <название>K05-361 - <студент name="Николай Иванов" born="1996" nomer_zachotkee="321205"/> + diff --git a/NVIvanov/mephi.xsd b/NVIvanov/mephi.xsd index 7123e78..3acdf51 100644 --- a/NVIvanov/mephi.xsd +++ b/NVIvanov/mephi.xsd @@ -33,6 +33,7 @@ + @@ -64,6 +65,7 @@ + From d3e4e68ea3439e93ad37f3978aab48cb2c54de45 Mon Sep 17 00:00:00 2001 From: Nikolay Ivanov Date: Tue, 13 Oct 2015 19:52:36 +0300 Subject: [PATCH 5/7] xpath1 --- NVIvanov/mephi.dtd | 15 ------------- NVIvanov/mephi.py | 52 +++++++++++++++++++++++++++++++++++++--------- NVIvanov/mephi.xml | 24 ++++++++++----------- 3 files changed, 54 insertions(+), 37 deletions(-) delete mode 100644 NVIvanov/mephi.dtd diff --git a/NVIvanov/mephi.dtd b/NVIvanov/mephi.dtd deleted file mode 100644 index 66d0a7f..0000000 --- a/NVIvanov/mephi.dtd +++ /dev/null @@ -1,15 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/NVIvanov/mephi.py b/NVIvanov/mephi.py index 8ddb4ef..332de93 100755 --- a/NVIvanov/mephi.py +++ b/NVIvanov/mephi.py @@ -5,6 +5,7 @@ import libxml2 import optparse + def get_property_by_name(node, name): for node_property in node.properties: if node_property.type == 'attribute' and node_property.name == name: @@ -73,22 +74,53 @@ def get_option_parser(): def xpath(xml_file, str1): - doc = libxml2.parseFile(xml_file) - ctxt = doc.xpathNewContext() - result = ctxt.xpathEval(str1) - for item in result: - print(item.content) - print - ctxt.xpathFreeContext() - doc.freeDoc() + result = xml_file.xpathEval(str1) + return result + + +def get_response_size(array): + return len(array) + + +def output_response(response): + if isinstance(response, list): + for item in response: + print(item.content) + else: + print(response) def main(argv): op = get_option_parser() options, arguments = op.parse_args() if options.xml and options.xsd: - xpath(options.xml, "/МИФИ/факультет/кафедра/title") - xpath(options.xml, "/МИФИ/факультет/каферда/группа/student[1]") + doc = libxml2.parseFile(options.xml) + ctxt = doc.xpathNewContext() + output_response(xpath(doc, "//department/title")) + output_response(xpath(doc, "//student[@entered > 2000]/@name")) + output_response(xpath(doc, "//department[./group/student/@name = 'Nikolay Ivanov']/title")) + output_response(get_response_size(xpath(doc, "//group[./title = 'K05-361']/student"))) + output_response(get_response_size(xpath(doc, "//department[./number = '36']/group/student"))) + + maximum = 0 + minimum = 0 + students_min = 100 + students_max = 0 + for i in range(1, get_response_size(xpath(doc, "//department"))): + path = xpath(doc, "//department[%s]/group/student" % i) + if students_max < get_response_size(path): + students_max = get_response_size(path) + maximum = i + if students_min > get_response_size(path): + students_min = get_response_size(path) + minimum = i + output_response(xpath(doc, "//department[%s]/group/student" % minimum)) + output_response(xpath(doc, "//department[%s]/group/student" % maximum)) + + output_response(xpath(doc, "//faculty[./department[./number = '36']]/title")) + + ctxt.xpathFreeContext() + doc.freeDoc() else: op.print_help() diff --git a/NVIvanov/mephi.xml b/NVIvanov/mephi.xml index 3ee8c1a..3bdb94c 100755 --- a/NVIvanov/mephi.xml +++ b/NVIvanov/mephi.xml @@ -1,16 +1,16 @@ -<МИФИ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + - <факультет> - <название>K - <кафедра> + + K + Информационные системы и технологии - <номер>36 - <группа> - <название>K05-361 - 36 + + K05-361 + - - - - \ No newline at end of file + + + + \ No newline at end of file From 58408cc345a39551232ddf400d3f9efe471ad68e Mon Sep 17 00:00:00 2001 From: Nikolay Ivanov Date: Tue, 20 Oct 2015 19:35:02 +0300 Subject: [PATCH 6/7] scripts --- NVIvanov/mephi.dtd | 17 ++++++++++++++++ NVIvanov/mephi.xml | 22 ++++++++++---------- NVIvanov/mephi.xsd | 27 ++++++++---------------- NVIvanov/mephi1.py | 35 ++++++++++++++++++++++++++++++++ NVIvanov/mephi2.py | 33 ++++++++++++++++++++++++++++++ NVIvanov/mephi3.py | 24 ++++++++++++++++++++++ NVIvanov/{mephi.py => mephi4.py} | 18 ++++++++-------- NVIvanov/mephi5.py | 26 ++++++++++++++++++++++++ NVIvanov/xslt_task1.xsl | 12 +++++++++++ 9 files changed, 175 insertions(+), 39 deletions(-) create mode 100644 NVIvanov/mephi.dtd mode change 100755 => 100644 NVIvanov/mephi.xml create mode 100755 NVIvanov/mephi1.py create mode 100644 NVIvanov/mephi2.py create mode 100644 NVIvanov/mephi3.py rename NVIvanov/{mephi.py => mephi4.py} (88%) mode change 100755 => 100644 create mode 100644 NVIvanov/mephi5.py create mode 100644 NVIvanov/xslt_task1.xsl diff --git a/NVIvanov/mephi.dtd b/NVIvanov/mephi.dtd new file mode 100644 index 0000000..25e4610 --- /dev/null +++ b/NVIvanov/mephi.dtd @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/NVIvanov/mephi.xml b/NVIvanov/mephi.xml old mode 100755 new mode 100644 index 3bdb94c..64b7edc --- a/NVIvanov/mephi.xml +++ b/NVIvanov/mephi.xml @@ -1,15 +1,15 @@ - - + + - - K - - Информационные системы и технологии - 36 - - K05-361 - + + + + + + + diff --git a/NVIvanov/mephi.xsd b/NVIvanov/mephi.xsd index 3acdf51..b4c38c2 100644 --- a/NVIvanov/mephi.xsd +++ b/NVIvanov/mephi.xsd @@ -10,33 +10,25 @@ + - + + - - - - - - - - - - - - + + @@ -44,8 +36,8 @@ - - + + @@ -53,9 +45,9 @@ - + @@ -64,8 +56,7 @@ - - + diff --git a/NVIvanov/mephi1.py b/NVIvanov/mephi1.py new file mode 100755 index 0000000..f321b01 --- /dev/null +++ b/NVIvanov/mephi1.py @@ -0,0 +1,35 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +import sys +import libxml2 + + +def parse_students(doc): + mephi = doc.getRootElement() + faculty = mephi.children + while faculty is not None: + if faculty.type == 'element': + department = faculty.children + while department is not None: + if department.type == 'element': + group = department.children + while group is not None: + if group.type == 'element': + student = group.children + while student is not None: + if student.type == 'element': + print(student.prop("name")) + student = student.next + group = group.next + department = department.next + faculty = faculty.next + + +def main(argv): + doc = libxml2.parseFile(argv[1]) + parse_students(doc) + doc.freeDoc() + +if __name__ == '__main__': + main(sys.argv) diff --git a/NVIvanov/mephi2.py b/NVIvanov/mephi2.py new file mode 100644 index 0000000..ef2b731 --- /dev/null +++ b/NVIvanov/mephi2.py @@ -0,0 +1,33 @@ +#!usr/bin/env python +# -*- coding: utf-8 -*- + +import libxml2 +import optparse + + +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) + if ret == 1: + print(U"Документ удовлетворяет типу") + dtd.freeDtd() + doc.freeDoc() + return ret + + +def main(): + 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: + validate(options.xml, options.dtd) + else: + op.print_help() + +if __name__ == '__main__': + main() diff --git a/NVIvanov/mephi3.py b/NVIvanov/mephi3.py new file mode 100644 index 0000000..4ceacbc --- /dev/null +++ b/NVIvanov/mephi3.py @@ -0,0 +1,24 @@ +#!usr/bin/env python +# -*- coding: utf-8 + +import sys +import libxml2 + + +def schema_validate(xml_file, xsd_file): + ctxt = libxml2.schemaNewParserCtxt(xsd_file) + schema = ctxt.schemaParse() + validationCtxt = schema.schemaNewValidCtxt() + res = validationCtxt.schemaValidateFile(xml_file, 0) + if res != 0: + print("VALIDATION FAILED") + else: + print("VALIDATED") + + +def main(argv): + schema_validate(argv[1], argv[2]) + + +if __name__ == '__main__': + main(sys.argv) diff --git a/NVIvanov/mephi.py b/NVIvanov/mephi4.py old mode 100755 new mode 100644 similarity index 88% rename from NVIvanov/mephi.py rename to NVIvanov/mephi4.py index 332de93..e9ba8ab --- a/NVIvanov/mephi.py +++ b/NVIvanov/mephi4.py @@ -1,7 +1,6 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -import sys import libxml2 import optparse @@ -66,10 +65,9 @@ def parse_xml(xml_file): def get_option_parser(): - op = optparse.OptionParser(description=U"Проверка на соответствие XSD", - prog="dtd", version="0.1", usage=U"%prog") + op = optparse.OptionParser(description=U"XPath запросы", + prog="xpath", version="0.1", usage=U"%prog") op.add_option("-x", "--xml", dest="xml", help=U"XML документ", metavar="XML_FILE") - op.add_option("-d", "--xsd", dest="xsd", help=U"XSD документ", metavar="XSD_FILE") return op @@ -90,15 +88,15 @@ def output_response(response): print(response) -def main(argv): +def main(): op = get_option_parser() options, arguments = op.parse_args() - if options.xml and options.xsd: + if options.xml: doc = libxml2.parseFile(options.xml) ctxt = doc.xpathNewContext() - output_response(xpath(doc, "//department/title")) + output_response(xpath(doc, "//department/@number")) output_response(xpath(doc, "//student[@entered > 2000]/@name")) - output_response(xpath(doc, "//department[./group/student/@name = 'Nikolay Ivanov']/title")) + output_response(xpath(doc, "//department[./group/student/@name = 'Nikolay Ivanov']/@number")) output_response(get_response_size(xpath(doc, "//group[./title = 'K05-361']/student"))) output_response(get_response_size(xpath(doc, "//department[./number = '36']/group/student"))) @@ -117,7 +115,7 @@ def main(argv): output_response(xpath(doc, "//department[%s]/group/student" % minimum)) output_response(xpath(doc, "//department[%s]/group/student" % maximum)) - output_response(xpath(doc, "//faculty[./department[./number = '36']]/title")) + output_response(xpath(doc, "//faculty[./department[@number = '36']]/@name")) ctxt.xpathFreeContext() doc.freeDoc() @@ -126,4 +124,4 @@ def main(argv): if __name__ == '__main__': - main(sys.argv) + main() diff --git a/NVIvanov/mephi5.py b/NVIvanov/mephi5.py new file mode 100644 index 0000000..f600539 --- /dev/null +++ b/NVIvanov/mephi5.py @@ -0,0 +1,26 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +import libxml2 +import libxslt +import sys + + +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): + transform(argv[1], argv[2], argv[3]) + + +if __name__ == '__main__': + main(sys.argv) diff --git a/NVIvanov/xslt_task1.xsl b/NVIvanov/xslt_task1.xsl new file mode 100644 index 0000000..6587f54 --- /dev/null +++ b/NVIvanov/xslt_task1.xsl @@ -0,0 +1,12 @@ + + + + + +

+
+ + + +
+
\ No newline at end of file From 4ad2163b01ecbbed75f256fba1442b3ae4c3c941 Mon Sep 17 00:00:00 2001 From: Nikolay Ivanov Date: Tue, 20 Oct 2015 19:59:37 +0300 Subject: [PATCH 7/7] xslt task 2 --- NVIvanov/xslt_task2.xsl | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 NVIvanov/xslt_task2.xsl diff --git a/NVIvanov/xslt_task2.xsl b/NVIvanov/xslt_task2.xsl new file mode 100644 index 0000000..2c8be17 --- /dev/null +++ b/NVIvanov/xslt_task2.xsl @@ -0,0 +1,24 @@ + + + + + + + +

Студенты

+ + + + + + + + + + + +
ИмяГруппа
+ + +
+
\ No newline at end of file