Compare commits

...

3 Commits

Author SHA1 Message Date
nikbel2004@outlook.com
851d8c0c6d Laboratory_3 2024-09-15 23:47:08 +04:00
nikbel2004@outlook.com
7849dd4531 Laboratory_2 2024-09-15 23:46:31 +04:00
nikbel2004@outlook.com
a0a3fd0be4 Laboratory_1 2024-09-15 23:43:56 +04:00
4 changed files with 154 additions and 0 deletions

15
Lab 3/library.dtd Normal file
View File

@ -0,0 +1,15 @@
<!DOCTYPE library [
<!ELEMENT library (book+)>
<!ELEMENT book (title, author, genre, year)>
<!ELEMENT title (#PCDATA)>
<!ELEMENT author (#PCDATA)>
<!ELEMENT genre (#PCDATA)>
<!ELEMENT year (#PCDATA)>
<!ATTLIST book ISBN CDATA #REQUIRED>
<!ATTLIST book available CDATA #REQUIRED>
<!ATTLIST book publisher CDATA #IMPLIED>
<!ATTLIST book language CDATA #IMPLIED>
]>

23
Lab 3/library.xml Normal file
View File

@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="library.xslt"?>
<?xml-model href="library.dtd" type="applecation/xml-dtd"?>
<library xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="library.xsd">
<book ISBN="978-3-16-148410-0" author="Leo Tolstoy" publisher="Penguin" language="English" available="yes">
<title>War and Peace</title>
<author>Leo Tolstoy</author>
<genre>Historical</genre>
<year>1869</year>
</book>
<book ISBN="978-5-17-085410-0" author="Alexander Pushkin" publisher="AST" language="Russian">
<title>The Captain's Daughter</title>
<author>Alexander Pushkin</author>
<genre>Novel</genre>
<year>1836</year>
</book>
<book ISBN="978-5-11-022410-0" available="yes" language="French">
<title>The Three Musketeers</title>
<author>Alexandre Dumas</author>
<genre>Historical novel</genre>
<year>1844</year>
</book>
</library>

68
Lab 3/library.xsd Normal file
View File

@ -0,0 +1,68 @@
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<!-- Определение элемента "library", который содержит один или более элементов "book" -->
<xs:element name="library">
<xs:complexType>
<xs:sequence>
<xs:element name="book" maxOccurs="unbounded" minOccurs="1">
<xs:complexType>
<xs:sequence>
<xs:element name="title">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:minLength value="5"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="author">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:minLength value="5"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="genre">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="Fiction"/>
<xs:enumeration value="Non-Fiction"/>
<xs:enumeration value="Fantasy"/>
<xs:enumeration value="Mystery"/>
<xs:enumeration value="History"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<!-- Описание для year -->
<xs:element name="year" type="xs:gYear"/>
<xs:element name="era">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="BC"/> <!-- До нашей эры -->
<xs:enumeration value="AD"/> <!-- Наша эра -->
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:sequence>
<xs:attribute name="ISBN">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="(\d{10}|\d{13})"/> <!-- Шаблон для ISBN-10 или ISBN-13 -->
</xs:restriction>
</xs:simpleType>
</xs:attribute>
<xs:attribute name="available" type="xs:boolean" use="required" />
<xs:attribute name="publisher" type="xs:string" use="optional" />
<xs:attribute name="language" type="xs:string" use="optional" />
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>

48
Lab 3/library.xslt Normal file
View File

@ -0,0 +1,48 @@
<?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>
<head>
<title>Library</title>
<style>
table {
width: 70%;
border-collapse: collapse;
margin: 20px auto;
}
th, td {
border: 1px solid black;
padding: 10px;
text-align: left;
}
th {
background-color: #9acd32;
}
</style>
</head>
<body>
<h2 style="text-align: center;">Library Books</h2>
<table>
<tr>
<th>Title</th>
<th>Author</th>
<th>Genre</th>
<th>Year</th>
</tr>
<!-- Цикл по элементам book -->
<xsl:for-each select="library/book">
<tr>
<td><xsl:value-of select="title"/></td>
<td><xsl:value-of select="author"/></td>
<td><xsl:value-of select="genre"/></td>
<td><xsl:value-of select="year"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>