0% found this document useful (0 votes)
8 views4 pages

XML and XSD Schema Examples

The document contains definitions for XML schemas (DTD and XSD) describing invoice and book management data structures. The DTD defines invoice line items and products. The XSD defines a book catalog with publishers, books, and relationships. An XSL stylesheet extracts publisher and book data from the XML based on conditions.

Uploaded by

ngocson160391
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views4 pages

XML and XSD Schema Examples

The document contains definitions for XML schemas (DTD and XSD) describing invoice and book management data structures. The DTD defines invoice line items and products. The XSD defines a book catalog with publishers, books, and relationships. An XSL stylesheet extracts publisher and book data from the XML based on conditions.

Uploaded by

ngocson160391
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd

Cu 1: DTD

<?xml version="1.0" encoding="UTF-8"?> <!ELEMENT DanhMucHoaDon (HoaDon+)> <!ELEMENT HoaDon (SoHD,Ngay,TongTien, CTHoaDon+)> <!ELEMENT SoHD (#PCDATA)> <!ELEMENT Ngay (#PCDATA)> <!ELEMENT TongTien (#PCDATA)> <!ELEMENT CTHoaDon (MatHang+)> <!ELEMENT MatHang (TenHang, SoLuong, DonGia)> <!ELEMENT TenHang (#PCDATA)> <!ELEMENT SoLuong (#PCDATA)> <!ELEMENT DonGia (#PCDATA)> XSD <?xml version="1.0" encoding="UTF-8"?> <xs:schema xmlns:xs="[Link] <xs:element name="DanhMucHoaDon"> <xs:complexType> <xs:sequence> <xs:element name="HoaDon" maxOccurs="unbounded"> <xs:complexType> <xs:sequence> <xs:element name="SoHD" type="xs:string"/> <xs:element name="Ngay" type="xs:date"/> <xs:element name="TongTien" type="xs:positiveInteger"/> <xs:element name="CTHoaDon"> <xs:complexType> <xs:sequence> <xs:element name="MatHang" maxOccurs="unbounded"> <xs:complexType> <xs:sequence> <xs:element name="TenHang" type="xs:string"/> <xs:element name="SoLuong" type="xs:positiveInteger"/> <xs:element name="DonGia" type="xs:positiveInteger"/> </xs:sequence> </xs:complexType> </xs:element> </xs:sequence> </xs:complexType> </xs:element> </xs:sequence> </xs:complexType> </xs:element>

</xs:sequence> </xs:complexType> </xs:element> </xs:schema> Cu 2: XSD <?xml version="1.0" encoding="UTF-8"?> <xs:schema xmlns:xs="[Link] elementFormDefault="qualified" attributeFormDefault="unqualified"> <xs:element name="QLSach"> <xs:complexType> <xs:sequence> <xs:element name="DMNhaXB" type="DMNhaXB"/> <xs:element name="DMSach" type="DMSach"/> </xs:sequence> </xs:complexType> <xs:key name="PK_NhaXB_MaNXB"> <xs:selector xpath="DMNhaXB/*"/> <xs:field xpath="MaNXB"/> </xs:key> <xs:key name="PK_Sach_MaSach"> <xs:selector xpath="DMSach/*"/> <xs:field xpath="@MaSach"/> </xs:key> <xs:keyref name="FK_NhaXB_MaNXB" refer="PK_NhaXB_MaNXB"> <xs:selector xpath="DMSach/*"/> <xs:field xpath="MaNXB"/> </xs:keyref> </xs:element> <xs:complexType name="DMSach"> <xs:sequence> <xs:element name="Sach" type="Sach" maxOccurs="unbounded"/> </xs:sequence> </xs:complexType> <xs:complexType name="NhaXB"> <xs:sequence> <xs:element name="MaNXB" type="xs:string"/> <xs:element name="TenNXB" type="xs:string"/> <xs:element name="DiaChi" type="xs:string"/> </xs:sequence> </xs:complexType> <xs:complexType name="Sach"> <xs:sequence> <xs:element name="TenSach" type="xs:string"/>

<xs:element name="SoTrang" type="xs:positiveInteger"/> <xs:element name="MaNXB" type="xs:string"/> </xs:sequence> <xs:attribute name="MaSach" type="xs:string"/> </xs:complexType> <xs:complexType name="DMNhaXB"> <xs:sequence> <xs:element name="NhaXB" type="NhaXB" maxOccurs="unbounded"/> </xs:sequence> </xs:complexType> </xs:schema> Truy vn XSL <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="[Link] <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/> <xsl:template match="/"> <xsl:for-each select="QLSach/DMNhaXB/NhaXB"> <xsl:if test="TenNXB = 'Thanh Nien'"> <xsl:variable name="NXBTN" select="MaNXB"/> </xsl:if> </xsl:for-each> <xsl:value-of select="NXBTN"></xsl:value-of> <HTML> <HEAD> <TITLE>ABC</TITLE> </HEAD> <BODY> <TABLE border="1"> <tr> <th>Ma Sach</th> <th>Ten sach</th> <th>So Trang</th> <th>Ma NXB</th> </tr> <xsl:for-each select="QLSach/DMSach/Sach"> <xsl:if test="MaNXB='A2'"> <TR> <TD><xsl:value-of select="@MaSach" /></TD> <TD><xsl:value-of select="TenSach" /></TD> <TD><xsl:value-of select="SoTrang" /></TD> <TD><xsl:value-of select="MaNXB" /></TD> </TR> </xsl:if> </xsl:for-each>

</TABLE> </BODY> </HTML> </xsl:template> </xsl:stylesheet> Cu 3: a. <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="[Link] <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/> <xsl:template match="/"> <html> <head> <title>count</title> </head> <body> <table border="1"> <tbody> <tr> <th>Ten</th> <th>Luong</th> </tr> <xsl:for-each select="//TongGiamDoc|//TruongPhong|//GiamDoc|//NhanVien|//ToTruong"> <tr> <td><xsl:value-of select="."></xsl:value-of></td> <td><xsl:value-of select="@Luong"></xsl:value-of></td> </tr> </xsl:for-each> </tbody> </table> </body> </html> </xsl:template> </xsl:stylesheet> b.

You might also like