XML - 資料交換管理/一對多關係
XML - 資料交換管理
|
相關主題
|
參與進來
|
| 上一章 | 下一章 |
| ← 基本資料結構 | 一對一關係 → |
|
學習目標
|
在一對多關係中,一個物件可以引用另一個物件的多個例項。模型對映到架構,其中每個資料模型實體都成為一個複雜元素型別。每個資料模型屬性都成為一個簡單元素型別,一對多關係記錄為一個序列。
圖 1:1:m 關係的資料模型
在上一章中,我們介紹了一個簡單的 XML 架構、XML 文件和用於單個實體資料模型的 XML 樣式表。現在,我們包含了 XML 的每個關鍵方面的更多功能。
有三種不同的技術可以實現一對多關係
包含關係:定義一個結構,其中一個元素包含在另一個元素中。“包含”元素在“容器”元素被刪除時將不再存在。例如,如果一個城市有多家酒店,則酒店“包含”在城市中。
<cityDetails>
<cityName>Belmopa</cityName>
<hotelDetails>
<hotelName>Bull Frog Inn</hotelName>
</hotelDetails>
<hotelDetails>
<hotelName>Pook's Hill Lodge</hotelName>
</hotelDetails>
</cityDetails>
<cityDetails>
<cityName>Kuala Lumpur</cityName>
<hotelDetails>
<hotelName>Pan Pacific Kuala Lumpur</hotelName>
</hotelDetails>
<hotelDetails>
<hotelName>Mandarin Oriental Kuala Lumpur</hotelName>
</hotelDetails>
</cityDetails>
文件內關係:如果您有一個城市有多家酒店,而不是一個城市包含酒店,那麼酒店將與城市具有“位於”關係。酒店元素上使用城市 ID 作為引用。因此,酒店不再包含在城市中,而是透過 cityRef 屬性引用城市的 ID。這非常類似於關係資料庫中的外部索引鍵。
<cityDetails>
<city ID="c1">
<cityName>Belmopa</cityName>
</city ID>
<city ID="c2">
<cityName>Kuala Lumpur</cityName>
</city ID>
</cityDetails>
<hotelDetails>
<hotel cityRef="c1">
<hotelName>Bull Frog Inn</hotelName>
</hotel>
<hotel cityRef="c2">
<hotelName>Pan Pacific Kuala Lumpur</hotelName>
</hotel>
</hotelDetails>
文件間關係:文件間關係與文件內關係非常相似。它也使用 id 和 idRef 屬性將屬性分配給父屬性。不同之處在於,文件間關係用於當表(例如城市和酒店表)可能位於不同的檔案系統或表空間中時。
<city id="c1">
<cityName>Belmopa</cityName>
</city>
<city id="c2">
<cityName>Kuala Lumpur</cityName>
</city>
<hotel>
<city href="cityDetails.xml#c1"/>
<hotelName>Bull Frog Inn</hotelName>
</hotel>
<hotel>
<city href="cityDetails.xml#c2"/>
<hotelName>Pan Pacific Kuala Lumpur</hotelName>
</hotel>
圖 2:決定使用哪種技術的清單
| 技術 | 傳遞資料 | 靈活性 | 易用性 |
|---|---|---|---|
| 包含 | 優秀 | 一般 | 優秀 |
| 文件內 | 良好 | 良好 | 良好 |
| 文件間 | 一般 | 優秀 | 一般 |
上一章介紹了一些 XML 架構的內建資料型別,但仍然有一些非常有用的資料型別,例如 anyURI、date、time、year 和 month。除了內建資料型別外,架構設計人員還可以定義自定義資料型別以接受特定的資料輸入。正如我們所學,資料在 XML 文件中使用 XML 架構中定義的標記標籤進行定義。但是,某些元素可能沒有值。空元素標籤可用於解決此情況。空元素標籤(以及任何自定義標記標籤)可以包含屬性,這些屬性可以新增有關標籤的其他資訊,而無需向元素新增額外的文字。本章將使用屬性在空元素標籤中顯示一個示例。
元素可以具有不同的內容型別,具體取決於每個元素在 XML 架構中的定義方式。不同的型別是元素內容、混合內容、簡單內容和空內容。XML 元素包含從元素標籤的開頭到該元素標籤的結尾的所有內容。
- 具有元素內容的元素是根元素 - 開標籤和閉標籤之間的所有內容僅包含元素。
| 示例 | <tourGuide> |
| </tourGuide> |
- 混合內容元素是在其開標籤和閉標籤之間包含文字以及其他元素的元素。
| 示例 | <restaurant>我最喜歡的餐廳是 |
| <restaurantName>Provino's Italian Restaurant</restaurantName> | |
| </restaurant> |
- 簡單內容元素是在其開標籤和閉標籤之間僅包含文字的元素。
| 示例 | <restaurantName>Provino's Italian Restaurant</restaurantName> |
- 空內容元素(即空元素)是在其開標籤和閉標籤之間不包含任何內容的元素(或者元素標籤透過在開標籤的結尾之前使用 / 來開啟和結束)。
| 示例 | <hotelPicture filename="pan_pacific.jpg" size="80" |
| value="Pan Pacific 的圖片"/> |
當不需要指定其內容或描述元素的資訊是固定的時,空元素很有用。兩個示例說明了這一概念。首先,一個圖片元素引用影像的源及其屬性,但不需要指定文字內容。其次,公司的所有者姓名是固定的,因此它可以使用屬性在 owner 標籤內指定相關資訊。屬性是元資訊,描述元素內容的資訊。
<?xml version="1.0" encoding="UTF-8"?>
<gesmes:Envelope xmlns:gesmes="http://www.gesmes.org/xml/2002-08-01"
xmlns="http://www.ecb.int/vocabulary/2002-08-01/eurofxref">
<gesmes:subject>Reference rates</gesmes:subject>
<gesmes:Sender>
<gesmes:name>European Central Bank</gesmes:name>
</gesmes:Sender>
<Cube>
<Cube time="2004-05-28">
<Cube currency="USD" rate="1.2246"/>
<Cube currency="JPY" rate="135.77"/>
<Cube currency="DKK" rate="7.4380"/>
<Cube currency="GBP" rate="0.66730"/>
<Cube currency="SEK" rate="9.1150"/>
<Cube currency="CHF" rate="1.5304"/>
<Cube currency="ISK" rate="87.72"/>
<Cube currency="NOK" rate="8.2120"/>
</Cube>
</Cube>
<!--For the sake of illustration, some of the currencies are omitted
in the preceding code.Banks, consultants, currency traders,
and firms involved in international trade are the major users
of this information.-->
</gesmes:Envelope>
第 2 章介紹了一些常用的資料型別,例如字串、十進位制、整數和布林值。以下是一些其他有用的資料型別。
圖 3:其他資料型別
| 型別 | 格式 | 示例 | 註釋 |
|---|---|---|---|
| year | YYYY | 1999 | |
| month | YYYY-MM | 1999-03 | 當日期對於資料元素不相關時,使用月型別 |
| time | hh:mm:ss.sss,帶可選時區指示符 | 20:14:05 | Z 表示 UTC,或 –hh:mm 或 +hh:mm 之一表示與 UTC 的差異。當您希望內容表示每天重複的特定時間(例如下午 4:15)時,使用此時間型別。 |
| date | YYYY-MM-DD | 1999-03-14 | |
| anyURI | 以 http:// 開頭的域名 | http://www.panpacific.com |
除了內建的資料型別外,還可以根據需要建立自定義資料型別。自定義資料型別可以是簡單型別或複雜型別。為簡單起見,我們建立一個作為簡單型別的自定義資料型別,這意味著該元素不包含其他元素或屬性。它僅包含文字。自定義簡單型別的建立從使用內建簡單型別開始,並應用限制(或方面)來限制標記的可接受值。自定義簡單型別可以是無名的或命名的。如果自定義簡單型別僅使用一次,則沒有必要為其命名;因此,該自定義型別僅在其定義的位置使用。由於命名的自定義型別可以被引用(透過其名稱),因此該自定義型別可以在任何需要的地方使用。
可以使用模式來精確指定元素內容的外觀。例如,可能需要指定電話號碼、郵政編碼或產品程式碼的格式。透過為某些元素定義模式,交換的資料將保持統一,並且儲存在資料庫中的值將保持一致。透過正則表示式設定模式是一種有用的方法,這將在後面的章節中討論。
以下是擴充套件上一章中介紹的模式的模式,其中包括城市到酒店的一對多關係,以及兩個自定義資料型別的示例。
圖 1:1:m 關係的資料模型
重要提示,這是一個持續的示例,因此新的程式碼將新增到上一章的示例中!
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" elementFormDefault="unqualified">
<!--Tour Guide-->
<xsd:element name="tourGuide">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="city" type="cityDetails" minOccurs="1" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<!--This will contain the City details-->
<xsd:complexType name="cityDetails">
<xsd:sequence>
<xsd:element name="cityName" type="xsd:string"/>
<xsd:element name="adminUnit" type="xsd:string"/>
<xsd:element name="country" type="xsd:string"/>
<!--The element Continent uses a Nameless Custom Simple Type-->
<xsd:element name="continent">
<xsd:simpleType>
<xsd:restriction base="xsd:string">
<xsd:enumeration value="Asia"/>
<xsd:enumeration value="Africa"/>
<xsd:enumeration value="Australia"/>
<xsd:enumeration value="Europe"/>
<xsd:enumeration value="North America"/>
<xsd:enumeration value="South America"/>
<xsd:enumeration value="Antarctica"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
<xsd:element name="population" type="xsd:integer"/>
<xsd:element name="area" type="xsd:integer"/>
<xsd:element name="elevation" type="xsd:integer"/>
<xsd:element name="longitude" type="xsd:decimal"/>
<xsd:element name="latitude" type="xsd:decimal"/>
<xsd:element name="description" type="xsd:string"/>
<xsd:element name="history" type="xsd:string"/>
<xsd:element name="hotel" type="hotelDetails" minOccurs="1" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
<!-- This will contain the Hotel details-->
<xsd:complexType name="hotelDetails">
<xsd:sequence>
<xsd:element name="hotelName" type="xsd:string"/>
<xsd:element name="hotelPicture"/>
<xsd:element name="streetAddress" type="xsd:string"/>
<xsd:element name="postalCode" type="xsd:string" minOccurs="0"/>
<xsd:element name="phone" type="xsd:string"/>
<xsd:element name="emailAddress" type="emailAddressType" minOccurs="0"/>
<!-- The custom simple type, emailAddressType, defined in the xsd:complexType,
is used as the type of the emailAddress element. -->
<xsd:element name="websiteURL" type="xsd:anyURI" minOccurs="0"/>
<xsd:element name="hotelRating" type="xsd:integer"/>
</xsd:sequence>
</xsd:complexType>
<!-- NOTE: Since postalCode, emailAddress, and websiteURL are not standard elements that
must be provided, the minOccurs=”0” indicates that they are optional -->
<!--This is a Named Custom SimpleType that is called from Hotel whenever someone types in an
email address-->
<xsd:simpleType name="emailAddressType">
<xsd:restriction base="xsd:string">
<!--You can learn more about this pattern by reading the Regex section.-->
<xsd:pattern value="\w+\W*\w*@{1}\w+\W*\w+.\w+.*\w*"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:schema>
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" elementFormDefault="unqualified">
<!--Tour Guide-->
<xsd:element name="tourGuide">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="city" type="cityDetails" minOccurs="1" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<!--This will contain the City details-->
<xsd:complexType name="cityDetails">
<xsd:sequence>
<xsd:element name="cityID" type="xsd:ID"/>
<xsd:element name="cityName" type="xsd:string"/>
<xsd:element name="adminUnit" type="xsd:string"/>
<xsd:element name="country" type="xsd:string"/>
<!--The element Continent uses a Nameless Custom Simple Type-->
<xsd:element name="continent">
<xsd:simpleType>
<xsd:restriction base="xsd:string">
<xsd:enumeration value="Asia"/>
<xsd:enumeration value="Africa"/>
<xsd:enumeration value="Australia"/>
<xsd:enumeration value="Europe"/>
<xsd:enumeration value="North America"/>
<xsd:enumeration value="South America"/>
<xsd:enumeration value="Antarctica"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
<xsd:element name="population" type="xsd:integer"/>
<xsd:element name="area" type="xsd:integer"/>
<xsd:element name="elevation" type="xsd:integer"/>
<xsd:element name="longitude" type="xsd:decimal"/>
<xsd:element name="latitude" type="xsd:decimal"/>
<xsd:element name="description" type="xsd:string"/>
<xsd:element name="history" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
<!-- This will contain the Hotel details-->
<xsd:complexType>
<xsd:sequence>
<xsd:element name="hotel" type="hotelDetails" minOccurs="1" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="hotelDetails">
<xsd:sequence>
<xsd:element name="cityRef" type="xsd:IDRef"/>
<xsd:element name="hotelName" type="xsd:string"/>
<xsd:element name="hotelPicture"/>
<xsd:element name="streetAddress" type="xsd:string"/>
<xsd:element name="postalCode" type="xsd:string" minOccurs="0"/>
<xsd:element name="phone" type="xsd:string"/>
<xsd:element name="emailAddress" type="emailAddressType" minOccurs="0"/>
<!-- The custom simple type, emailAddressType, defined in the xsd:complexType,
is used as the type of the emailAddress element. -->
<xsd:element name="websiteURL" type="xsd:anyURI" minOccurs="0"/>
<xsd:element name="hotelRating" type="xsd:integer"/>
</xsd:sequence>
</xsd:complexType>
<!-- NOTE: Since postalCode, emailAddress, and websiteURL are not standard elements that
must be provided, the minOccurs=”0” indicates that they are optional -->
<!--This is a Named Custom SimpleType that is called from Hotel whenever someone types in an
email address-->
<xsd:simpleType name="emailAddressType">
<xsd:restriction base="xsd:string">
<!--You can learn more about this pattern by reading the Regex section.-->
<xsd:pattern value="\w+\W*\w*@{1}\w+\W*\w+.\w+.*\w*"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:schema>
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" elementFormDefault="unqualified">
<!--Tour Guide-->
<xsd:element name="tourGuide">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="city" type="cityDetails" minOccurs="1" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<!--This will contain the City details-->
<xsd:complexType name="cityDetails">
<xsd:sequence>
<xsd:element name="cityID" type="xsd:ID"/>
<xsd:element name="cityName" type="xsd:string"/>
<xsd:element name="adminUnit" type="xsd:string"/>
<xsd:element name="country" type="xsd:string"/>
<!--The element Continent uses a Nameless Custom Simple Type-->
<xsd:element name="continent">
<xsd:simpleType>
<xsd:restriction base="xsd:string">
<xsd:enumeration value="Asia"/>
<xsd:enumeration value="Africa"/>
<xsd:enumeration value="Australia"/>
<xsd:enumeration value="Europe"/>
<xsd:enumeration value="North America"/>
<xsd:enumeration value="South America"/>
<xsd:enumeration value="Antarctica"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
<xsd:element name="population" type="xsd:integer"/>
<xsd:element name="area" type="xsd:integer"/>
<xsd:element name="elevation" type="xsd:integer"/>
<xsd:element name="longitude" type="xsd:decimal"/>
<xsd:element name="latitude" type="xsd:decimal"/>
<xsd:element name="description" type="xsd:string"/>
<xsd:element name="history" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
<!-- This will contain the Hotel details-->
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" elementFormDefault="unqualified">
<!--Tour Guide 2-->
<xsd:element name="tourGuide2">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="hotel" type="hotelDetails" minOccurs="1" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="hotelDetails">
<xsd:sequence>
<xsd:element name="cityRef" type="xsd:IDRef"/>
<xsd:element name="hotelName" type="xsd:string"/>
<xsd:element name="hotelPicture"/>
<xsd:element name="streetAddress" type="xsd:string"/>
<xsd:element name="postalCode" type="xsd:string" minOccurs="0"/>
<xsd:element name="phone" type="xsd:string"/>
<xsd:element name="emailAddress" type="emailAddressType" minOccurs="0"/>
<!-- The custom simple type, emailAddressType, defined in the xsd:complexType,
is used as the type of the emailAddress element. -->
<xsd:element name="websiteURL" type="xsd:anyURI" minOccurs="0"/>
<xsd:element name="hotelRating" type="xsd:integer"/>
</xsd:sequence>
</xsd:complexType>
<!-- NOTE: Since postalCode, emailAddress, and websiteURL are not standard elements that
must be provided, the minOccurs=”0” indicates that they are optional -->
<!--This is a Named Custom SimpleType that is called from Hotel whenever someone types in an
email address-->
<xsd:simpleType name="emailAddressType">
<xsd:restriction base="xsd:string">
<!--You can learn more about this pattern by reading the Regex section.-->
<xsd:pattern value="\w+\W*\w*@{1}\w+\W*\w+.\w+.*\w*"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:schema>
參考第 2 章 - 使用 NetBeans 建立上述 XML 模式的方法的單個實體。
屬性
- 有效的元素命名結構也適用於屬性名稱。
- 在給定的元素中,所有屬性的名稱必須唯一。
- 屬性不能包含符號“<” 。可以使用字元字串“<” 來表示它。
- 每個屬性必須具有名稱和值。(例如 <hotelPicture filename=“pan_pacific.jpg” />,filename 是名稱,pan_pacific.jpg 是值)
- 如果分配的值本身包含帶引號的字串,則引號型別必須與用於括起整個值的引號型別不同。(例如,如果使用雙引號括起整個值,則對字串使用單引號:<name familiar=”’Jack’”>John Smith</name>)
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="city_hotel.xsl"?>
<tourGuide xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="TourGuide3.xsd">
<!--This is where you define the first city and all its attributes-->
<city>
<cityName>Belmopa</cityName>
<adminUnit>Cayo</adminUnit>
<country>Belize</country>
<!--The content of the element “continent” must be one of the values specified in the set of
acceptable values in the XML schema for the element “continent”-->
<continent>South America</continent>
<population>11100</population>
<area>5</area>
<elevation>130</elevation>
<longitude>12.3</longitude>
<latitude>123.4</latitude>
<description>Belmopan is the capital of Belize</description>
<history>Belmopan was established following devastation of the former capitol, Belize City ,
by Hurricane Hattie in 1965. High ground and open space influenced the choice and
ground-breaking began in 1966. By 1970 most government offices and operations had
already moved to the new location. </history>
<!--This is where you would store the name of the Hotel and its attributes-->
<!--Notice that the hotelDetails elements did not contain the postalCode entity. The document is
still valid, because postalCode is optional-->
<hotel>
<hotelName>Bull Frog Inn</hotelName>
<!--The empty element, hotelPicture, contains attributes: “filename”, “size”, and “value”, to
indicate the name and location of the image file, the desired size, and
the description of the empty element, hotelPicture-->
<hotelPicture filename="bull_frog_inn.jpg" size="80" value="Image of Bull Frog Inn"
imageURL="http://www.bullfroginn.com"/>
<streetAddress>25 Half Moon Avenue</streetAddress>
<phone>501-822-3425</phone>
<!--The emailAddress elements must match the pattern specified in the schema to be valid -->
<emailAddress>bullfrog@btl.net</emailAddress>
<websiteURL>http://www.bullfroginn.com/</websiteURL>
<hotelRating>4</hotelRating>
</hotel>
<!--This is where you put the information for another Hotel-->
<hotel>
<hotelName>Pook's Hill Lodge</hotelName>
<hotelPicture filename="pook_hill_lodge.jpg" size="80" value="Image of Pook's Hill
Lodge" imageURL="http://www.global-travel.co.uk/pook1.htm"/>
<streetAddress>Roaring River</streetAddress>
<phone>440-126-854-1732</phone>
<emailAddress>info@global-travel.co.uk</emailAddress>
<websiteURL>http://www.global-travel.co.uk/pook1.htm</websiteURL>
<hotelRating>3</hotelRating>
</hotel>
</city>
<!--This is where you define another city and its attributes-->
<city>
<cityName>Kuala Lumpur</cityName>
<adminUnit>Selangor</adminUnit>
<country>Malaysia</country>
<continent>Asia</continent>
<population>1448600</population>
<area>243</area>
<elevation>111</elevation>
<longitude>101.71</longitude>
<latitude>3.16</latitude>
<description>Kuala Lumpur is the capital of Malaysia and is the largest city in the nation.
</description>
<history>The city was founded in 1857 by Chinese tin miners and superseded Klang. In 1880
the British government transferred their headquarters from Klang to Kuala Lumpur , and
in 1896 it became the capital of Malaysia. </history>
<!--This is where you put the information for a Hotel-->
<hotel>
<hotelName>Pan Pacific Kuala Lumpur </hotelName>
<hotelPicture filename="pan_pacific.jpg" size="80" value="Image of Pan Pacific"
imageURL="http://www.malaysia-hotels-discount.com/hotels/kualalumpur/pan_pacific_hotel/index.shtml"/>
<streetAddress>Jalan Putra</streetAddress>
<postalCode>50746</postalCode>
<phone>1-866-260-0402</phone>
<emailAddress>president@panpacific.com</emailAddress>
<websiteURL>http://www.panpacific.com</websiteURL>
<hotelRating>5</hotelRating>
</hotel>
<!--This is where you put the information for another Hotel-->
<hotel>
<hotelName>Mandarin Oriental Kuala Lumpur </hotelName>
<hotelPicture filename="mandarin_oriental.jpg" size="80" value="Image of Mandarin
Oriental" imageURL="http://www.mandarinoriental.com/kualalumpur"/>
<streetAddress>Kuala Lumpur City Centre</streetAddress>
<postalCode>50088</postalCode>
<phone>011-603-2380-8888</phone>
<emailAddress>mokul-sales@mohg.com</emailAddress>
<websiteURL>http://www.mandarinoriental.com/kualalumpur/</websiteURL>
<hotelRating>5</hotelRating>
</hotel>
</city>
</tourGuide>
表 3-2:一對多關係的 XML 文件 - city_hotel.xml
參考第 2 章 - 使用 NetBeans 建立上述 XML 文件的方法的單個實體。
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="html"/>
<xsl:template match="/">
<html>
<head>
<title>Tour Guide</title>
</head>
<body>
<h2>Cities</h2>
<xsl:apply-templates select="tourGuide"/>
</body>
</html>
</xsl:template>
<xsl:template match="tourGuide">
<xsl:for-each select="city">
<xsl:text>City: </xsl:text>
<xsl:value-of select="cityName"/>
<br/>
<xsl:text>Population: </xsl:text>
<xsl:value-of select="population"/>
<br/>
<xsl:text>Country: </xsl:text>
<xsl:value-of select="country"/>
<br/>
<xsl:for-each select="hotel">
<xsl:text>Hotel: </xsl:text>
<xsl:value-of select="hotelName"/>
<br/>
</xsl:for-each>
<br/>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
| 除了簡單的內建資料型別(例如,年份、月份、時間、anyURI 和日期)外,模式設計人員還可以建立自定義資料型別以滿足其需求。可以透過應用一些限制、方面(指定一組可接受值的列舉)或特定模式來從內建資料型別之一建立簡單的自定義資料型別。 空元素不包含任何文字,但是,它可能包含屬性以提供有關該元素的其他資訊。 顯示 HTML 頁面的呈現佈局可以包括樣式標籤、背景顏色、字型大小、字型粗細和對齊方式的程式碼。可以使用表格標籤來組織 HTML 頁面內容的佈局,並且還可以使用影像標籤顯示影像。 |
為了進一步瞭解一對多關係,提供了練習。
為了進一步瞭解一對多關係,提供了答案與上述練習相對應。