XML - Managing Data Exchange/The one-to-many relationship



Previous Chapter Next Chapter
Basic data structures The one-to-one relationship




Learning objectives

  • Learn different techniques of implementing one-to-many relationships in XML
  • create custom data types in an XML schema
  • create empty elements with attributes in an XML document
  • define a presentation layout for an XML document using a table with varying background colors and font characteristics, and display images in an XML stylesheet



Introduction edit

In a one-to-many relationship, one object can reference several instances of another. A model is mapped into a schema whereby each data model entity becomes a complex element type. Each data model attribute becomes a simple element type, and the one-to-many relationship is recorded as a sequence.

Exhibit 1:Data model for 1:m relationship


In the previous chapter, we introduced a simple XML schema, XML document, and an XML stylesheet for a single entity data model. We now include more features of each of the key aspects of XML.

Implementing a one-to-many relationship edit

There are three different techniques for implementing a one-to-many relationship:

Containment relationship: A structure is defined where one element is contained within another. The "contained" element ceases to exist when the "container" element is removed. For instance, where a city has many hotels, the hotels are "contained" in the city.

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

Intra-document relationships: In a case where you have one city with many hotels, rather than a city containing hotels, a hotel will have a "location in" relationship to a city. A city id is used as a reference on the hotel element. Therefore, rather than the hotels being contained in the city, they now just reference the city's id via the cityRef attribute. This is very similar to a foreign key in a relational database.

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

Inter-document relationships: The inter-document relationship is much like the intra-document relationship. It also uses the id and idRef attributes to assign an attribute to a parent attribute. The difference is that the inter-document relationship is used when tables, such as the city and hotel tables, might live in different filesystems or tablespaces.

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


Exhibit 2:Checklist for deciding what technique to use:

Technique Passing Data Flexibility Ease of Use
Containment Excellent Fair Excellent
Intra-Document Good Good Good
Inter-Document Fair Excellent Fair

XML schema edit

Some of the built-in data types for an XML schema were introduced in the previous chapter, but still, there are more that are very useful, such as anyURI, date, time, year, and month. In addition to the built-in data types, a custom data type can be defined by the schema designer to accept specific data input. As we have learned, data are defined in XML documents using markup tags defined in an XML schema. However, some elements might not have values. An empty element tag can be used to address this situation. An empty element tag (and any custom markup tag) can contain attributes that add additional information about the tag without adding extra text to the element. An example will be shown in the chapter, using attributes in an empty element tag.

Empty elements with attributes in XML document edit

Elements can have different content types depending on how each element is defined in the XML schema. The different types are element content, mixed content, simple content, and empty content. An XML element consists of everything from the start of the element tag to the close of that element tag.

  • An element with element content is the root element - everything in between the opening and closing tags consists of elements only.
Example:<tourGuide>
     :
 </tourGuide>
  • A mixed content element is one that has text and as well as other elements between its opening and closing tags.
Example:<restaurant>My favorite restaurant is
 <restaurantName>Provino's Italian Restaurant</restaurantName>
     :
 </restaurant>
  • A simple content element is one that contains only text between its opening and closing tags.
Example: <restaurantName>Provino's Italian Restaurant</restaurantName>
  • An empty content element, which is an empty element, is one that does not contain anything between its opening and closing tags (or the element tag is opened and ended with a single tag, by using / before the closing of the opening tag.
Example: <hotelPicture filename="pan_pacific.jpg" size="80"
         value="Image of Pan Pacific"/>

An empty element is useful when there is no need to specify its content or that the information describing the element is fixed. Two examples illustrated this concept. First, a picture element that references the source of an image with its attributes, but has no need in specifying text content. Second, the owner’s name is fixed for a company, thus it can specify the related information inside the owner tag using attributes. An attribute is meta-information, information that describes the content of the element.

European Central Bank's use of XML edit

<?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>

XML schema data types edit

Some of the commonly used data types, such as string, decimal, integer, and boolean, are introduced in chapter 2. The following are a few more data types that are useful.

Exhibit 3:Other data types:

Type Format Example Comment
year YYYY 1999  
month YYYY-MM 1999-03 Month type is used when the day is irrelevant for the data element
time hh:mm:ss.sss with optional time zone indicator 20:14:05 Z for UTC or one of –hh:mm or +hh:mm to indicate the difference from UTC. This time type is used when you want the content to represent a particular time of day that recurs every day, such as 4:15 pm.
date YYYY-MM-DD 1999-03-14  
anyURI The domain name specified beginning with http:// http://www.panpacific.com  

More data types edit

Besides the built-in data types, custom data types can be created as required. A custom data type can be a simple type or complex type. For simplicity, we create a custom data type that is a simple type, which means that the element does not contain other elements or attributes. It contains text only. The creation of a custom simple type starts from using a built-in simple type and applying it with restrictions, or facets, to limit the acceptable values of the tag. A custom simple type can be nameless or named. If the custom simple type is to be used only once, then it makes sense to not name it; thus, that custom type will only be used in where it is defined. Since a named custom type can be referenced (by its name), that custom type can be used wherever necessary.

A pattern can be used to specify exactly how the content of the element should look. For example, one might want to specify the format of a telephone number, a postal code, or a product code. By having a defined pattern for certain elements, the data exchanged will be uniform and the values will be consistent when stored in a database. A useful way to set patterns is through Regex, which will be discussed in later chapters.

Schema examples edit

The following is a schema that extends the schema introduced in the previous chapter to include a one-to-many relationship of city to hotels with two examples of custom data types.

Exhibit 1:Data model for 1:m relationship

1:m relationship - City Hotel

Important, this is a continuing example, so new code is added to the last chapter's example!

Containment example edit

 <?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>

Intra-document example edit

 <?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>

Inter-document example edit

<?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>

Refers to Chapter 2 - A single entity for steps in using NetBeans to create the above XML schema.

XML document edit

Attributes

  • The valid element naming structure applies to attribute names as well
  • In a given element, all attributes’ names must be unique
  • An attribute may not contain the symbol ‘<’ The character string ‘&lt;’ can be used to represent it
  • Each attribute must have a name and a value. (i.e. <hotelPicture filename=“pan_pacific.jpg” />, filename is the name and pan_pacific.jpg is the value)
  • If the assigned value itself contains a quoted string, the type of quotation marks must differ from those used to enclose the entire value. (For instance, if double quotes are used to enclose the whole value then use single quotes for the string: <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>

Table 3-2: XML Document for a one-to-many relationship – city_hotel.xml

Refers to Chapter 2 - A single entity for steps in using NetBeans to create the above XML document.

XML style sheet edit

<?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>

Summary edit

Besides the simple built-in data types (e.g, year, month, time, anyURI, and date) schema designers may create custom data types to suit their needs. A simple custom data type can be created from one of the built-in data types by applying to it some restrictions, facets (enumerations that specify a set of acceptable values), or specific patterns.

An empty element does not contain any text, however, it may contain attributes to provide additional information about that element.

The presentation layout for displaying a HTML page can include code for style tags, background color, font size, font weight, and alignment. Table tags can be used to organize the layout of content in a HTML page, and images can also be displayed using an image tag.



Exercises edit

In order to learn more about the one-to-many relationship, exercises are provided.

Answers edit

In order to learn more about the one-to-many relationship, answers are provided to go with the exercises above.