Home > Articles > Web Services > XML

  • Print
  • + Share This
This chapter is from the book

This chapter is from the book

3.10 Summary examples

This section presents examples of complete documents that bring together everything we've discussed in the last two chapters (and more). The content is fictitious, but the structure and markup are from real web site projects (somewhat abridged for readability).

3.10.1 Page document

Compared to the master document example (3.10.2), the page document in Example 3.1 is short and simple. This is, in fact, what you should strive for in your project. Page documents are the primary work area for those who will update and maintain the site, so the layout of a page document must be as simple and self-evident as possible. (For instance: Do we need indentation in page documents? Probably not, unless it is taken care of automatically.)

The main rule of thumb is: If you can move a bit of information away from a page document to the master or to the stylesheet, do that.

3.10.2 Master document

Example 3.2 shows a master document that compiles most of the data we discussed in 3.9 but adds a few new twists.

Languages. Our example site is bilingual (English and German), so all titles and labels are provided in two languages, and the languages themselves are listed in a languages element. We add an internal DTD subset with mnemonic entity references ( for German characters.

Environments. For every installation where the site can be built, an environment element with a unique id supplies the following information:

  • src-path is the base directory of the XML source documents tree.
  • Example 3.1 en/team/index.xml: A page document

    <?xml version="1.0" encoding="us-ascii"?>
    <page keywords="team, people, staff, competences, skills">
    <title>Our team</title>
    <!-- Main content block: -->
    <block type="body">
    <p>With backgrounds in technology and communications, FooBar's
    experienced management team has - you guessed it -
    <em>the right combination of skills for success</em>.</p>
    <section image="mike">
    <head>Mike M. Anager</head> 
    <p>CEO and Co-Founder, Mike leads FooBar towards bringing the vision
    of "personal foobar" to reality. He previously served as Chief
    Architect at <ext link="www.barfoo.com">BarFoo Corporation</ext>.</p>
    <section image="ed">
    <head>Ed N. Gineer</head> 
    <subhead>VP, Engineering</subhead>
    <p>Ed has over 30 years of foobar design experience under his
    belt. He has personally contributed to the most acclaimed of 
    our <int link="solutions">products</int>, including the famous
    <int link="fbplus">Foobar Plus</int>.</p>
    <section image="jack">
    <head>Jack J. Anitor</head> 
    <subhead>Senior Janitor</subhead>
    <p>Jack's expert janitorial skills and experience have been
    critical in the success of FooBar.</p> 
    <!-- Orthogonal content blocks: -->
    <block idref="subscribe"/>
    <block idref="feature"/>
  • out-path is the directory where the output files will be placed (used in batch mode, 5.6). It is also assumed that the images subdirectory (img-path) is under out-path.

  • img-path is where all the images (both static and generated) are stored. This path is relative to out-path.

  • target-path is the common part of all URIs used in the resulting HTML files to refer to images or other pages of the site. Thus, if you transform and view your pages locally at out-path, then target-path may be the same as out-path. If, however, you are going to upload the transformed site to a directory on a web server and access it at, say, http://www.example.org/test/, then target-path may be either /test/ (for absolute pathnames starting with /) or an empty string (for relative pathnames). URIsabsolute URIsrelative

On Windows, all absolute paths must be given in the file:/ URL format.17 This is the only standard and reliable way to represent an absolute pathname that includes a drive letter. In HTML, URLs with file:/ work for both links and image references in all browsers we tested. Other platforms may use absolute pathnames without the file:/.

Menu. The menu lists all the pages of the site. For each page, the src attribute contains the page's pathname (add .xml for source files or .html for output files) relative to the site's root directory.

Each page has an id attribute used to link to it. To make life easier, you can also provide a space-separated list of aliases in the alias attribute. In internal links to this page, you can use either its id or any of the aliases.

Each menu item has a label child storing the item's visible label. In the menu on a web page, each item is supposed to be linked to its first page child, so there's no need to specify a link in an item.

It is assumed that the English and German versions of the source files are named the same but stored in different directory trees under the root directory. The corresponding directories are named after the language designations defined in languages. So, for instance, the complete path to the German fbplus source page in the staging environment would be constructed as follows:


Blocks. The blocks element holds a list of orthogonal content blocks with their identifiers (id), source document locations (src), and block selectors (select, Note that the subscribe page is listed only once as an orthogonal source, while the solutions/foobar_plus page is both in the menu and in the blocks list. For this reason, a block must specify a complete location for the orthogonal content source and not just its id, as all other links do, because not all orthogonal documents are registered in the menu and assigned an id.

Misc. Finally, the master document lists the common part to be prepended to page titles (3.2.4) on all pages (html-title), page footer content (page-footer), and two labels for buttons that need to be created by the stylesheet (buttons).

Note that the mailto links used in page-footer represent a special link type (3.5.2, page 109) with an abbreviated address (the corresponding resolved URI will have mailto: prepended to the email address).

Example 3.2 _master.xml: The master document.

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE site [
  <!ENTITY auml "ä">
  <!ENTITY ouml "ö">
  <!ENTITY uuml "ü">

  <!-- Environments: -->
  <environment id="local">
  <environment id="staging">
  <environment id="final">

  <!-- Languages: -->

  <!-- Menu: -->
        <translation lang="en">Home</translation>
        <translation lang="de">Home</translation>
      <page id="home" alias="index front fp frontpage" src="index"/> 
        <translation lang="en">Solutions</translation>
        <translation lang="de">L&ouml;sungen</translation>
      <page id="solutions" src="solutions/intro_solutions"/>
          <translation lang="en">Life</translation>
          <translation lang="de">Das Leben</translation>
        <page id="life" src="solutions/life"/>
        <page id="fbplus" alias="foobar_plus fb+ foobar+" 
        <page id="fbminus" src="solutions/foobar_minus"/>
      <page id="universe" src="solutions/universe"/>
      <page id="everything" src="solutions/everything"/>
        <translation lang="en">Our team</translation>
        <translation lang="de">Unser Team</translation>
      <page id="team" src="team/index"/>
      <page id="history" src="team/history"/>      
      <page id="hire" src="team/hire"/>      
        <translation lang="en">Contact</translation>
        <translation lang="de">Kontakt</translation>
      <page id="contact" src="contact/contact"/>
      <page id="map" src="contact/map"/>

  <!-- Orthogonal and dynamic blocks: -->
    <!-- Extract the 'summary' block from the product page: -->
    <block id="feature" src="solutions/foobar_plus" 
    <!-- Extract the 'last' block from the front page: -->
    <block id="news" src="index" select="last"/>
    <!-- Take the entire subscribe.xml: -->
    <block id="subscribe" src="subscribe"/>
    <!-- Run site map generation: -->
    <block-process id="sitemap" process="sitemap" 
                                mode="text" depth="2"/>
    <!-- Run list-titles on all files in news/: -->
    <block-process id="news-list" process="list-titles" 

  <!-- The common part of the page titles: -->
    <translation lang="en">Foobar Corporation AG</translation>
    <translation lang="de">Foobar Corporation AG</translation>

  <!-- Page footer content: -->
      <translation lang="en">&#169; 2003 by Foobar Corporation AG. 
        All rights reserved.</translation>
      <translation lang="de">&#169; 2003 by Foobar Corporation AG. 
        All rights reserved.</translation>
      <translation lang="en">
        <lang link="de">Diese Seite in deutsch</lang>
      <translation lang="de">
        <lang link="en">This page in English</lang>
      <translation lang="en">
        Problems using this site? Contact the 
        <mailto link="webmaster@foobar.com">Webmaster</mailto>.
      <translation lang="de">
        Probleme mit dieser Web-Site? Kontaktieren Sie bitte unseren 
        <mailto link="webmaster@foobar.com">Webmaster</mailto>.

  <!-- Sequence navigation buttons: -->
    <button id="prev">
      <translation lang="en">prev</translation>
      <translation lang="de">zur&uuml;ck</translation>
    <button id="next">
      <translation lang="en">next</translation>
      <translation lang="de">vorw&auml;rts</translation>


3.10.3 Schematron schema

The schema in Example 3.3 is used to validate both the master document and page documents of our Foobar site. This makes sense because these document types have a lot in common. Still, for readability the schema is broken into three patterns: One tests the master document, another tests page documents, and the last one tests constructs that occur in both document types (this includes links, images, and text markup).

Languages. The lang-check abstract rule checks that the element being checked contains exactly as many translation children as there are languages defined in the languages element. This rule can then be reused for any element that provides information in two languages. A separate rule with context="translation" additionally checks that the lang attributes correspond to the defined languages and that each language version is provided only once.

Element presence. In this schema, many element-presence checks are lumped together for simplicity (e.g., all children of an environment are checked in one assert). This does not have to be that way; if you want your schema to be really helpful, you can write a separate check with its own diagnostic message for each element type, explaining its role and the possible consequences of its being missing from the source.

Context-sensitive checks. Note that there are two different page element types: One is used in the master document, and the other is the root element type in a page document. The same applies to blocks. The schema, however, has no problems differentiating between these element types based on the context.

Reporting unknowns. One function of a schema is to check for unknown element type names (most often resulting from typos). In Schematron, this can be implemented by providing a dummy rule with no tests, listing all defined element types as possible contexts. Following that, a rule with context="*" signals error whenever the rule is activated. This technique is possible because each context will only match one rule per pattern; if an element was not matched by the dummy rule, it is caught by the next rule and reported as unrecognized.

It's only a beginning. This example schema demonstrates only the basic, most critical checks. Your own schema may be significantly larger and more detailed than this, although it will likely use mostly the same techniques. Consider this schema a phrasebook with common expressions for typical situations. Several advanced tricks for validating complex constraints are discussed in Chapter 5 (5.1.3).

Example 3.3 schema.sch: A Schematron schema for validating page documents and the master document.

<schema xmlns="http://www.ascc.net/xml/schematron">

<!-- Checks for the master document: -->
<pattern name="master">

<rule context="site">
  <report test="count(//environment) = 1">
    Only one 'environment' found; you will need to create more if you 
    want to build the site in a different environment.
  <report test="count(//environment) = 0">

    No 'environment' elements found; the stylesheet will be unable to  
    figure out pathnames.
  <assert test="languages and menu and html-title and page-footer 
                          and blocks">
    One of the required elements not found inside 'site'.

<rule context="page-footer">
  <assert test="copyright and language-switch
                          and contact-webmaster">
    One of the required elements not found inside 'page-footer'.

<rule context="environment">
  <assert test="src-path and out-path 
                and target-path and img-path and os">
    One of the required elements not found inside 'environment'.
  <assert test="@id">
    An 'environment' must have an 'id' attribute.
  <assert test="count(//environment/@id[. = current()/@id]) = 1"> 
    The 'id' attribute value of an 'environment' must be unique.

<rule context="src-path | img-path | out-path | target-path">
  <report test="*">
    The '<name/>' element cannot have children.
  <report test="(normalize-space(.) = '') 
                and not(name() = 'target-path')">
    The '<name/>' element cannot be empty.

<rule context="languages">
  <assert test="count(lang) = count (*)">
    The 'languages' element can only have 'lang' children.
  <assert test="count(lang) > 0">
    The 'languages' element must have at least one 'lang' child.

<rule context="languages/lang">
  <assert test="count(//languages/lang[. = current()]) = 1"> 
    Each language must be specified only once.

<rule context="menu">
  <assert test="count(item) = count (*)">
    The 'menu' element cannot contain elements other than 'item'.

<rule context="item">
  <assert test="label" diagnostics="label-element">
    A 'label' element is missing.
  <report test="count(label) &gt; 1" diagnostics="label-element">
    There is an extra 'label' element.
  <assert test="page">
    At least one 'page' element should be specified within an 'item'.

<rule context="menu//page">
  <assert test="@src">
    Each 'page' must have an 'src' attribute.
  <assert test="@id">
    Each 'page' must have a unique 'id' attribute.
  <assert test="count(//page/@id[. = current()/@id]) = 1"> 
    The 'id' attribute value of a 'page' must be unique.

<!-- Abstract rule to check 'transformation' children: -->
<rule abstract="true" id="lang-check">
  <assert test="count(translation) = count(//languages/lang)">
    The number of 'translation' children in '<name/>' must correspond
    to the number of defined languages. If this element does not 
    exist in one of the languages, use an empty 'translation' element.
  <assert test="count(translation) = count(*)">
    There must be no child elements here other than 'translation'.

<!-- Applying the abstract rule to all bilingual elements: -->
<rule context="label | html-title | copyright 
               | language-switch | contact-webmaster | button">
  <extends rule="lang-check"/>

<rule context="translation">
  <assert test="@lang">
    Each 'translation' must have a 'lang' attribute.
  <assert test="@lang = //languages/lang/text()">
    The value of the 'lang' attribute must correspond to one of the 
    defined languages.
  <report test="@lang = preceding-sibling::translation/@lang">
    There is another 'translation' element under this parent with the 
    same value of the 'lang' attribute.

<rule context="blocks">
  <report test="*[not(self::block or self::block-process)]">
    A 'blocks' element must only contain one or more 'block' or 
    'block-process' elements.

<rule context="blocks/block">
  <assert test="@id and @src">
    A 'block' defined in the master document must have both 'id' and 
    'src' attributes.
  <assert test="count(//blocks/block/@id[. = current()/@id]) = 1"> 
    The 'id' attribute value of a 'block' must be unique.


<!-- Checks for page documents: -->
<pattern name="page">

<rule context="/page">
  <assert test="@keywords">
    Please consider adding a list of keywords to the page. Use a 
    'keywords' attribute for that.
  <assert test="title">
    Each 'page' must have a 'title'.
  <assert test="count(title) &lt; 2">
    A 'page' may have only one 'title'.
  <assert test="block">
    Each 'page' must have at least one 'block'.

<rule context="page//block">
  <assert test="@idref or *">
    A block must have either an 'idref' attribute (referring to an 
    orthogonal block) or children.
  <report test="@idref and *">
    A block cannot have both an 'idref' attribute and children.
  <report test="count(p | section) < count(*)">
    A block can only have 'p' or 'section' children.

<rule context="section">
  <assert test="head">
    A section must have a 'head'.
  <assert test="p">
    A section must have at least one 'p' (paragraph).
  <assert test="normalize-space(text()) = ''">
    A section cannot contain text. Use a 'p' element to include a 
    paragraph of text.


<!-- Rules common for master and page documents: -->
<pattern name="common">

<rule context="int | link[@linktype='internal']">
  <assert test="@link">
    An internal link must use a 'link' attribute to specify the 
    page being linked.

<rule context="p">
  <report test="(normalize-space(text()) = '') and not(*)">
    A paragraph cannot be empty. If you want to increase vertical 
    spacing here, modify the stylesheet.

<!-- Dummy rule listing all defined element types: --> 
<rule context="
    block | block-process | blocks | button | buttons |
    contact-webmaster | copyright | environment | em | ext | head |
    html-title | img-path | int | item | label | lang |
    language-switch | languages | link | mailto | menu | os |
    out-path | p | page | page-footer | site | section | src-path |
    subhead | target-path | title | translation"/>

<!-- Report error if an element was not matched by the above: -->
<rule context="*">
  <report test="true()">
    Unrecognized element: '<name/>'.


  <diagnostic id="label-element">
    Every 'item' element must contain exactly one 'label' element 
    specifying the corresponding top menu label.

  • + Share This
  • 🔖 Save To Your Account

InformIT Promotional Mailings & Special Offers

I would like to receive exclusive offers and hear about products from InformIT and its family of brands. I can unsubscribe at any time.


Pearson Education, Inc., 221 River Street, Hoboken, New Jersey 07030, (Pearson) presents this site to provide information about products and services that can be purchased through this site.

This privacy notice provides an overview of our commitment to privacy and describes how we collect, protect, use and share personal information collected through this site. Please note that other Pearson websites and online products and services have their own separate privacy policies.

Collection and Use of Information

To conduct business and deliver products and services, Pearson collects and uses personal information in several ways in connection with this site, including:

Questions and Inquiries

For inquiries and questions, we collect the inquiry or question, together with name, contact details (email address, phone number and mailing address) and any other additional information voluntarily submitted to us through a Contact Us form or an email. We use this information to address the inquiry and respond to the question.

Online Store

For orders and purchases placed through our online store on this site, we collect order details, name, institution name and address (if applicable), email address, phone number, shipping and billing addresses, credit/debit card information, shipping options and any instructions. We use this information to complete transactions, fulfill orders, communicate with individuals placing orders or visiting the online store, and for related purposes.


Pearson may offer opportunities to provide feedback or participate in surveys, including surveys evaluating Pearson products, services or sites. Participation is voluntary. Pearson collects information requested in the survey questions and uses the information to evaluate, support, maintain and improve products, services or sites, develop new products and services, conduct educational research and for other purposes specified in the survey.

Contests and Drawings

Occasionally, we may sponsor a contest or drawing. Participation is optional. Pearson collects name, contact information and other information specified on the entry form for the contest or drawing to conduct the contest or drawing. Pearson may collect additional personal information from the winners of a contest or drawing in order to award the prize and for tax reporting purposes, as required by law.


If you have elected to receive email newsletters or promotional mailings and special offers but want to unsubscribe, simply email information@informit.com.

Service Announcements

On rare occasions it is necessary to send out a strictly service related announcement. For instance, if our service is temporarily suspended for maintenance we might send users an email. Generally, users may not opt-out of these communications, though they can deactivate their account information. However, these communications are not promotional in nature.

Customer Service

We communicate with users on a regular basis to provide requested services and in regard to issues relating to their account we reply via email or phone in accordance with the users' wishes when a user submits their information through our Contact Us form.

Other Collection and Use of Information

Application and System Logs

Pearson automatically collects log data to help ensure the delivery, availability and security of this site. Log data may include technical information about how a user or visitor connected to this site, such as browser type, type of computer/device, operating system, internet service provider and IP address. We use this information for support purposes and to monitor the health of the site, identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents and appropriately scale computing resources.

Web Analytics

Pearson may use third party web trend analytical services, including Google Analytics, to collect visitor information, such as IP addresses, browser types, referring pages, pages visited and time spent on a particular site. While these analytical services collect and report information on an anonymous basis, they may use cookies to gather web trend information. The information gathered may enable Pearson (but not the third party web trend services) to link information with application and system log data. Pearson uses this information for system administration and to identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents, appropriately scale computing resources and otherwise support and deliver this site and its services.

Cookies and Related Technologies

This site uses cookies and similar technologies to personalize content, measure traffic patterns, control security, track use and access of information on this site, and provide interest-based messages and advertising. Users can manage and block the use of cookies through their browser. Disabling or blocking certain cookies may limit the functionality of this site.

Do Not Track

This site currently does not respond to Do Not Track signals.


Pearson uses appropriate physical, administrative and technical security measures to protect personal information from unauthorized access, use and disclosure.


This site is not directed to children under the age of 13.


Pearson may send or direct marketing communications to users, provided that

  • Pearson will not use personal information collected or processed as a K-12 school service provider for the purpose of directed or targeted advertising.
  • Such marketing is consistent with applicable law and Pearson's legal obligations.
  • Pearson will not knowingly direct or send marketing communications to an individual who has expressed a preference not to receive marketing.
  • Where required by applicable law, express or implied consent to marketing exists and has not been withdrawn.

Pearson may provide personal information to a third party service provider on a restricted basis to provide marketing solely on behalf of Pearson or an affiliate or customer for whom Pearson is a service provider. Marketing preferences may be changed at any time.

Correcting/Updating Personal Information

If a user's personally identifiable information changes (such as your postal address or email address), we provide a way to correct or update that user's personal data provided to us. This can be done on the Account page. If a user no longer desires our service and desires to delete his or her account, please contact us at customer-service@informit.com and we will process the deletion of a user's account.


Users can always make an informed choice as to whether they should proceed with certain services offered by InformIT. If you choose to remove yourself from our mailing list(s) simply visit the following page and uncheck any communication you no longer want to receive: www.informit.com/u.aspx.

Sale of Personal Information

Pearson does not rent or sell personal information in exchange for any payment of money.

While Pearson does not sell personal information, as defined in Nevada law, Nevada residents may email a request for no sale of their personal information to NevadaDesignatedRequest@pearson.com.

Supplemental Privacy Statement for California Residents

California residents should read our Supplemental privacy statement for California residents in conjunction with this Privacy Notice. The Supplemental privacy statement for California residents explains Pearson's commitment to comply with California law and applies to personal information of California residents collected in connection with this site and the Services.

Sharing and Disclosure

Pearson may disclose personal information, as follows:

  • As required by law.
  • With the consent of the individual (or their parent, if the individual is a minor)
  • In response to a subpoena, court order or legal process, to the extent permitted or required by law
  • To protect the security and safety of individuals, data, assets and systems, consistent with applicable law
  • In connection the sale, joint venture or other transfer of some or all of its company or assets, subject to the provisions of this Privacy Notice
  • To investigate or address actual or suspected fraud or other illegal activities
  • To exercise its legal rights, including enforcement of the Terms of Use for this site or another contract
  • To affiliated Pearson companies and other companies and organizations who perform work for Pearson and are obligated to protect the privacy of personal information consistent with this Privacy Notice
  • To a school, organization, company or government agency, where Pearson collects or processes the personal information in a school setting or on behalf of such organization, company or government agency.


This web site contains links to other sites. Please be aware that we are not responsible for the privacy practices of such other sites. We encourage our users to be aware when they leave our site and to read the privacy statements of each and every web site that collects Personal Information. This privacy statement applies solely to information collected by this web site.

Requests and Contact

Please contact us about this Privacy Notice or if you have any requests or questions relating to the privacy of your personal information.

Changes to this Privacy Notice

We may revise this Privacy Notice through an updated posting. We will identify the effective date of the revision in the posting. Often, updates are made to provide greater clarity or to comply with changes in regulatory requirements. If the updates involve material changes to the collection, protection, use or disclosure of Personal Information, Pearson will provide notice of the change through a conspicuous notice on this site or other appropriate way. Continued use of the site after the effective date of a posted revision evidences acceptance. Please contact us if you have questions or concerns about the Privacy Notice or any objection to any revisions.

Last Update: November 17, 2020