Xml book cover wiki.png XML – Managing Knowledge Change Associated Matters Get Concerned

Studying targets

  • introduce XML paperwork, schemas, and stylesheets
  • describe and create an XML doc
  • describe and create an XML schema
  • describe and create an XML stylesheet


On this chapter, we begin to follow working with XML utilizing XML paperwork, schemas, and stylesheets. An XML doc organizes information and knowledge in a structured, hierarchical format. An XML schema supplies requirements and guidelines for the construction of a given XML doc. An XML schema additionally allows information switch. An XSL (XML stylesheet) permits distinctive shows of the fabric discovered inside an XML doc.

Within the first chapter, Introduction to XML, you discovered what XML is, why it’s helpful, and the way it’s used. So, now you wish to create your very personal XML paperwork. On this chapter, we are going to present you the essential parts used to create an XML doc. This chapter is the muse for all subsequent chapters–it is a bit of prolonged, however do not be intimidated. We’ll take you thru the basics of XML paperwork.

This chapter is split into three components:

  • XML Doc
  • XML Schema
  • XML Stylesheets (XSL)

As you discovered within the earlier chapter, the XML Schema and Stylesheet are primarily specialised XML Paperwork. Inside every of those three components we are going to look at the format and parts required to create the doc. There are hyperlinks on the finish of the XML doc, schema, and stylesheet sections that present you the way to create the paperwork utilizing an XML editor. On the backside of the web page there’s a hyperlink to Workout routines for this chapter and a hyperlink to the Solutions.

The very first thing you’ll need earlier than beginning to create XML paperwork is a problem–something you wish to remedy through the use of XML to retailer and share information or info. You want some entity you’ll be able to gather details about after which entry in a wide range of codecs. So, we created one for you.

To develop an XML doc and schema, begin with a knowledge mannequin depicting the truth of the particular information that’s exchanged. As soon as a excessive constancy mannequin has been created, the info mannequin will be readily transformed to an XML doc and schema. On this chapter, we begin with a quite simple scenario and in successive chapters lengthen the complexity to show you extra options of XML.

Our start line is a single entity, CITY, which is proven within the following determine. Whereas our focus is on this single entity, to map CITY to an XML schema, we have to have an entity that incorporates CITY. On this case, we’ve created TOURGUIDE. Consider a TOURGUIDE as containing many cities, and on this case TOURGUIDE has no attributes nor an identifier. It’s only a container for information about cities.

Exhibit 1: Knowledge mannequin – Tourguide

Data Model - Tourguide.png

XML doc[edit]

An XML doc is a file containing XML code and syntax. XML paperwork have an .xml file extension.

We’ll look at the options & parts of the XML doc.

  • Prologue (XML Declaration)
  • Parts
  • Attributes
  • Guidelines to comply with
  • Properly-formed & Legitimate XML paperwork

Beneath is a pattern XML doc utilizing our TourGuide mannequin. We’ll confer with it as we describe the components of an XML doc.

Exhibit 2: XML doc for metropolis entity

        Belmopan is the capital of Belize
        Belmopan was established following the devastation of the
           former capital, Belize Metropolis, by Hurricane Hattie in 1965. Excessive 
           floor and open area influenced the selection and ground-breaking 
           started in 1966.  By 1970 most authorities workplaces and operations had 
           already moved to the brand new location.
        Kuala Lumpur
        Kuala Lumpur is the capital of Malaysia and the biggest 
            metropolis within the nation
        Town was based in 1857 by Chinese language tin miners and  
            preceded Klang.  In 1880 the British authorities transferred their 
            headquarters from Klang to Kuala Lumpur, and in 1896 it turned the 
            capital of Malaysia. 
        St. Boniface
        Winnipeg has two seasons. Winter and Development.
        Town was based by folks on the forks (Fort Garry)
         buying and selling in pelts with the Hudson Bay Firm. Paradoxically, 
         The Bay was purchased by America.

Prologue (XML declaration)[edit]

The XML doc begins off with the prologue. The prologue informs each a reader and the pc of sure specs that make the doc XML compliant. The primary line is the XML declaration (and the one line on this fundamental XML doc).

Exhibit 3: XML doc – prologue


xml   =   that is an XML doc
model=”1.0″   =   the XML model (XML 1.Zero is the W3C-recommended model)
encoding=”UTF-8″   =   the character encoding used within the doc – UTF Eight corresponds to 8-bit encoded Unicode characters (i.e. the usual approach to encode worldwide paperwork) – Unicode supplies a novel quantity for each character.
One other potential attribute of the XML declaration:
standalone=”sure”   =   the dependency of the doc (‘sure’ signifies that the doc doesn’t require one other doc to finish content material)


Nearly all of what you see within the XML doc consists of XML components. Parts are recognized by their tags that open with < or shut with > or />. The begin tag seems to be like this: , with a left angle bracket (<) adopted by the aspect kind identify, elective attributes, and eventually a proper angle bracket (>). The finish tag seems to be like this: , just like the beginning tag, however with a slash (/) between the left angle bracket and the aspect kind identify, and no attributes.

When there’s nothing between a begin tag and an finish tag, XML means that you can mix them into an empty aspect tag, which might embody every part a begin tag can: . This one tag should be closed with a slash and proper angle bracket (/>), in order that it may be distinguished from a begin tag.

The XML doc is designed round a serious theme, an umbrella idea protecting all different objects and topics; this theme is analyzed to find out its element components, creating classes and subcategories. The key theme and its element components are described by components. In our pattern XML doc, ‘tourGuide’ is the key theme; ‘metropolis’ is a class; ‘inhabitants’ is a subcategory of ‘metropolis’; and the hierarchy could also be carried even additional: ‘males’ and ‘females’ may very well be subcategories of ‘inhabitants’. Parts comply with a number of guidelines of syntax that will likely be described within the Guidelines to Comply with part.

We ignored the attributes throughout the begin tag — that half will likely be defined within the XML Schema part.

Exhibit 4: Parts of the town entity XML doc

        Belmopan is the capital of Belize
        Belmopan was established following the devastation of the
           former capital, Belize Metropolis, by Hurricane Hattie in 1965. Excessive 
           floor and open area influenced the selection and ground-breaking 
           started in 1966.  By 1970 most authorities workplaces and operations had 
           already moved to the brand new location.

Ingredient hierarchy[edit]

  • root aspect  –   That is the XML doc’s main theme aspect. Each doc should have precisely one and just one root aspect. All different components are contained inside this one root aspect. The foundation aspect follows the XML declaration. In our instance, is the basis aspect.
  • father or mother aspect  –   That is any aspect that incorporates different components, the kid components. In our instance, is a father or mother aspect.
  • baby aspect  –   That is any aspect that’s contained inside one other aspect, the father or mother aspect. In our instance, is a toddler aspect of .
  • sibling aspect  –   These are components that share the identical father or mother aspect. In our instance, , , , ,
    , , , , , and are all sibling components.


Attributes support in modifying the content material of a given aspect by offering extra or required info. They’re contained throughout the aspect’s opening tag. In our pattern XML doc code we might have taken benefit of attributes to specify the unit of measure used to find out the world and the elevation (it may very well be ft, yards, meters, kilometers, and so forth.); on this case, we might have referred to as the attribute ‘measureUnit’ and outlined it throughout the opening tag of ‘space’ and ‘elevation’.


The above attribute instance can be written as:

1. utilizing baby components


2. utilizing an empty aspect


Attributes can be utilized to:

  • present extra info that’s not outlined within the information
  • outline a attribute of the aspect (measurement, colour, model)
  • make sure the inclusion of details about a component in all cases

Attributes can, nonetheless, be a bit harder to govern they usually have some constraints. Think about using a toddler aspect when you want extra freedom.

Guidelines to comply with[edit]

These guidelines are designed to assist the pc studying your XML doc.

  • The primary line of an XML doc should be the XML declaration (the prologue).
  • The principle theme of the XML doc is established within the root aspect and all different components should be contained throughout the opening and shutting tags of this root aspect.
  • Each aspect should have a gap tag and a closing tag – no exceptions

(e.g. information stuff).

  • Tags should be nested in a selected order

=> the father or mother aspect’s opening and shutting tags should include all of its baby components’ tags; on this means, you shut first the tag that was opened final:


  • Attribute values ought to have citation marks round them and no areas.
  • Empty tags or empty components should have an area and a slash (/) on the finish of the tag.
  • Feedback within the XML language start with ““.

XML Ingredient Naming Conference[edit]

Any identify can be utilized however the thought is to make names significant to those that may learn the doc.

  • XML components might solely begin with both a letter or an underscore character.
  • The identify should not begin with the string “xml” which is reserved for the XML specification.
  • The identify might not include areas.
  • The “:” shouldn’t be utilized in aspect names as a result of it’s reserved for use for namespaces (This will likely be coated in additional element in a later chapter).
  • The identify might include a mix of letters, numbers, or different characters.

XML paperwork usually have a corresponding database. The database will include fields which correspond to components within the XML doc. A great follow is to make use of the naming guidelines of your database for the weather within the XML paperwork.

DTD (Doc Kind Definition) Validation – Easy Instance[edit]

Easy Inner DTD[edit]
    </span>Darkish Facet of the Moon<span class="nt">
    Pink Floyd

Each aspect that will likely be used MUST be included within the DTD. Don’t neglect to incorporate the basis aspect, despite the fact that you might have already specified it initially of the DTD. You should specify it once more, in an tag.
The foundation aspect, , incorporates all the opposite components of the doc, however just one direct baby aspect: . Subsequently, it’s good to specify the kid aspect (solely direct baby components must be specified) within the parentheses.
With this line, we outline the aspect. Be aware that this aspect incorporates the kid components , <artist>, and <year>. These are spelled out in a selected order. This order should be adopted when creating the XML doc. When you change the order of the weather (with this explicit DTD), the doc gained’t validate.<br /> <!ELEMENT title (#PCDATA)> The remaining three tags, <title>, <artist>, and <year> don’t really include different tags. They do nonetheless include some textual content that must be parsed. It’s possible you’ll bear in mind from an earlier lecture that this information is known as Parsed Character Knowledge, or #PCDATA. Subsequently, #PCDATA is specified within the parentheses.<br /> So this easy DTD outlines precisely what you see right here within the XML file. Nothing will be added or taken away, so long as we stick with this DTD. The one factor you’ll be able to change is the #PCDATA textual content half between the tags. </p> <h5><span class="mw-headline" id="Adding_complexity">Including complexity</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span>edit<span class="mw-editsection-bracket">]</span></span></h5> <p>There could also be instances when it would be best to put extra than simply character information, or extra than simply baby components into a selected aspect. That is known as blended content material. For instance, let’s say you need to have the ability to put character information OR a toddler aspect, such because the <b> tag right into a <description> aspect: </p> <pre> <!ELEMENT description (#PCDATA | b | i )*> </pre> <p>This explicit association permits us to make use of PCDATA, the <b> tag, or the <i> tag unexpectedly. One explicit caveat although, is that if you’re going to combine PCDATA and different components, the grouping should be adopted by the asterisk suffix. This declaration permits us to now add the next to the XML doc (after defining the person components after all) </p> <div class="mw-highlight mw-highlight-lang-xml mw-content-ltr" dir="ltr"> <pre><span/> <span class="nt"><cd></span> <span class="nt"><title></span>Love. Angel. Music. Child<span class="nt"> Gwen Stefani 2004 pop It is a nice album from former No Doubt singer Gwen Stephani.

With attributes that is accomplished a bit of otherwise than with components. Please see following instance:

    </span>Darkish Facet of the Moon<span class="nt">
    Pink Floyd

To ensure that this to validate, it should be specified within the DTD. Attribute content material fashions are specified with:


Let’s use this to validate our CD instance:

Grouping Attributes for an Ingredient[edit]

If a selected aspect is to have many various attributes, group them collectively like so:

Including STATIC validation, for objects that should have a sure worth[edit]


So what occurs with our final instance with the CD assortment, once we wish to add extra CDs? With the present DTD, we can not add any extra CDs with out getting an error. Strive it and see.
If you specify a toddler aspect (or components) the way in which we did, solely one among every baby aspect can be utilized. Not very appropriate for a CD assortment is it?
We are able to use one thing referred to as suffixes so as to add performance to the tag.
Suffixes are added to the top of the required baby aspect(s). There are Three essential suffixes that can be utilized:

  • ( No suffix ): Just one baby can be utilized.
  • ( + ): A number of components can be utilized.
  • ( * ): Zero or extra components can be utilized.
  • ( ? ): Zero or one aspect could also be used.
Validating for a number of youngsters with a DTD[edit]

So within the case of our CD assortment XML file, we are able to add extra CDs to the record by including a + suffix:

Utilizing extra inside formatting tags[edit]

Daring tags, B’s for instance are additionally outlined within the DTD as components, which might be elective like thus:



   Wonderful , Kenneth is doing properly.
and so forth

Case Research on BMEcat[edit]

One of many first main nationwide tasks for the usage of XML as a B2B alternate format was initiated by the federal affiliation for materials administration, buying and logistics (BME) in cooperation with main German firms, e.g. Bayer, BMW, SAP and Siemens. All of them created a typical for the alternate of product catalogues. This undertaking was named BMEcat. The results of this initiative is a DTD assortment for the outline of product catalogues and associated transactions (new catalogue, updating of product information and updating of costs).

Corporations working within the digital commerce (suppliers, buying firms and market locations) alternate more and more massive quantities of information. They rapidly attain their limits right here by the number of information alternate codecs. The BMEcat answer creates a foundation for an easy switch of catalogue information from varied information codecs. This lays the muse to bringing ahead the products visitors via the Web in Germany. The usage of the BMEcat reduces the prices for all events as commonplace interfaces can be utilized.

The XML-based commonplace BMEcat was efficiently carried out in lots of tasks. These days a wide range of firms applies BMEcat and use it for the alternate of their product catalogs on this established commonplace.

A BMEcat catalogue (Model 1.2) consists of the next essential components:

This aspect incorporates the important info of a procuring catalog, e.g. language model and validity. BMEcat expects precisely one language per catalog.

This aspect contains identification and handle of the catalog suppliers. BMEcat expects precisely one provider per catalog.

This aspect incorporates the identify and handle of {the catalogue} recipient. BMEcat expects no a couple of recipient per catalog.

This aspect incorporates a number of framework settlement IDs related to the suitable validity interval. BMEcat expects all costs of a listing belonging to the contract talked about above.

This aspect permits the total switch of a number of classification programs, together with characteristic definitions and key phrases.

This aspect originates from model 1.0. It’s primarily used for the switch of tree-structures which facilitate the navigation of a person within the goal system (Browser).

ARTICLE (since 2005 PRODUCT)
This aspect represents a product. It incorporates a set of normal attributes.

This aspect represents a value. The assist of various pricing fashions may be very highly effective as compared with different alternate codecs. Season costs, nation costs, completely different currencies and completely different validity intervals, and so forth. will likely be supported.

This aspect permits the switch of attribute values. You may both document predefined group traits or particular person product traits.

This aspect permits itemizing of product variants, with out having to duplicate them. Nonetheless, the variations of BMEcat solely apply to particular person adjustments in worth, resulting in a change of Article ID. In any other case there can’t exist any dependences on different attributes (particularly at costs).

This aspect contains any variety of extra paperwork similar to product photos, information sheets, or web sites.

This aspect permits cross-referencing between articles inside a listing in addition to between catalogues. These references might used restrictedly for mapping product bundles.

This aspect allows transportation of information on the exterior the BMEcat requirements. The transmitter and receiver should be coordinated.

You could find a typical BMEcat file right here.

ONLINE Validator[edit]


Properly-formed and legitimate XML[edit]

Properly-formed XML  –  An XML doc that appropriately abides by the foundations of XML syntax.

Legitimate XML  –  An XML doc that adheres to the foundations of an XML schema (which we are going to focus on shortly). To be legitimate an XML doc should first be well-formed.

A Legitimate XML Doc should be Properly-formed. However, a Properly-formed XML Doc won’t be legitimate – in different phrases, a well-formed XML doc, that meets the standards for XML syntax, won’t meet the standards for the XML schema, and can due to this fact be invalid.

For instance, consider the scenario the place your XML doc incorporates the next (for this schema):

    United States

Discover that the weather don’t seem within the right sequence in response to the schema (cityName, adminUnit, nation). The XML doc will be validated (utilizing validation software program) towards its declared schema – the validation software program would then catch the out of sequence error.

Utilizing an XML Editor[edit]

Examine chapter XML Editor for directions on the way to begin an XML editor.
After you have adopted the steps to get began you’ll be able to copy the code within the pattern XML doc and paste it into the XML editor. Then verify your outcomes. Is the XML doc well-formed? Is the XML doc legitimate? (you’ll need to have copied and pasted the schema with the intention to validate – we are going to take a look at schemas subsequent)

XML schema[edit]

An XML schema is an XML doc. XML schemas have an .xsd file extension.

An XML schema is used to control the construction and content material of an XML doc by offering a template for XML paperwork to comply with with the intention to be legitimate. It’s a information for the way to construction your XML doc in addition to indicating your XML doc’s parts (components and attributes – and their relationships). An XML editor will look at an XML doc to make sure that it conforms to the specs of the XML schema it’s written towards – to make sure it’s legitimate.

XML schemas engender confidence in information switch. With schemas, the receiver of information can really feel assured that the info conforms to expectations. The sender and the receiver have a mutual understanding of what the info symbolize.

As a result of an XML schema is an XML doc, you employ the identical language – commonplace XML markup syntax – with components and attributes particular to schemas.

A schema defines:

  • the construction of the doc
  • the weather
  • the attributes
  • the kid components
  • the variety of baby components
  • the order of components
  • the names and contents of all components
  • the info kind for every aspect

For extra detailed info on XML schemas and reference lists of: Frequent XML Schema Primitive Knowledge Varieties, Abstract of XML Schema Parts, Schema Restrictions and Aspects for information varieties, and Occasion Doc Attributes, click on on this wikibook hyperlink => http://en.wikibooks.org/wiki/XML_Schema

Schema reference=[edit]

That is the a part of the XML Doc that references an XML Schema:

Exhibit 5: XML doc’s schema reference


That is the half we ignored once we described the basis aspect within the fundamental XML doc from the earlier part. The extra attributes of the basis aspect reference the XML schema (it’s the schemaLocation attribute).

xmlns:xsi=’http://www.w3.org/2001/XMLSchema-instance’  –  references the W3C Schema-instance namespace
xsi:noNamespaceSchemaLocation=’metropolis.xsd’  –  references the XML schema doc (metropolis.xsd)

Schema doc[edit]

Beneath is a pattern XML schema utilizing our TourGuide mannequin. We’ll confer with it as we describe the components of an XML schema.

Exhibit 6: XML schema doc for metropolis entity

                 identify="metropolis" kind="cityDetails" minOccurs = "1" maxOccurs="unbounded" />
              identify="cityName" kind="xsd:string"/>
              identify="adminUnit" kind="xsd:string"/>
              identify="nation" kind="xsd:string"/>
              identify="inhabitants" kind="xsd:integer"/>
              identify="space" kind="xsd:integer"/>
              identify="elevation" kind="xsd:integer"/>
              identify="longitude" kind="xsd:decimal"/>
              identify="latitude" kind="xsd:decimal"/>
              identify="description" kind="xsd:string"/>
              identify="historical past" kind="xsd:string"/>


Keep in mind that the XML schema is actually an XML doc and due to this fact should start with the prolog, which within the case of a schema contains:

  • the XML declaration
  • the schema aspect declaration

The XML declaration:


The schema aspect declaration:

 xmlns:xsd="http://www.w3.org/2001/XMLSchema" elementFormDefault="unqualified">

The schema aspect is just like a root aspect – it incorporates all different components within the schema.

Attributes of the schema aspect embody:

xmlns  –  XML NameSpace – the URL for the location that describes the XML components and information varieties used within the schema.

You could find extra about namespaces right here => Namespace.

xmlns:xsd  –  All the weather and attributes with the ‘xsd’ prefix adhere to the vocabulary designated within the given namespace.

elementFormDefault  –  components from the goal namespace are both required or not required to be certified with the namespace prefix. That is largely helpful when a couple of namespace is referenced. On this case, ‘elementFormDefault’ should be certified, since you should point out which namespace you might be utilizing for every aspect. In case you are referencing just one namespace, then ‘elementFormDefault’ will be unqualified. Maybe, utilizing certified because the default is most prudent, this fashion you don’t by accident neglect to point which namespace you might be referencing.

Ingredient declarations[edit]

Outline the weather within the schema.


  • the aspect identify
  • the aspect information kind (elective)

Fundamental aspect declaration format: identify="identify" kind="kind">

Easy kind[edit]

declares components that:

  • do NOT have Little one Parts
  • do NOT have Attributes

instance: identify="cityName" kind="xsd:string" />

Default Worth

If a component isn’t assigned a price then the default worth is assigned.

instance: identify="description" kind="xsd:string" default="actually cool place to go to!" />

Fastened Worth

An attribute that’s outlined as mounted should be empty or contained the required mounted worth. No different values are allowed.

instance: identify="description" kind="xsd:string" '''mounted="you should go to this place - it's superior!"''' />

Advanced kind[edit]

declares components that:

  • can have Little one Parts
  • can have Attributes


1. The foundation aspect ‘tourGuide’ incorporates a toddler aspect ‘metropolis’. That is proven right here:

Anonymous advanced kind

                 identify="metropolis" kind="cityDetails" minOccurs = "1" maxOccurs="unbounded" />

Incidence Indicators:

  • minOccurs = the minimal variety of instances a component can happen (right here it’s 1 time)
  • maxOccurs = the utmost variety of instances a component can happen (right here it’s a limiteless variety of instances, ‘unbounded’)

2. The father or mother aspect ‘metropolis’ incorporates many baby components: ‘cityName’, ‘adminUnit’, ‘nation’,
‘inhabitants’, and so forth. Why does this advanced aspect set not begin with the road: identify="metropolis" kind="cityDetails">? The aspect ‘metropolis’ was already outlined above throughout the advanced aspect ‘tourGuide’ and it was given the sort, ‘cityDetails’. This information kind, ‘cityDetails’, is utilized right here in figuring out the sequence of kid components for the father or mother aspect ‘metropolis’.

Named Advanced Kind – and due to this fact will be reused in different components of the schema

              identify="cityName" kind="xsd:string"/>
              identify="adminUnit" kind="xsd:string"/>
              identify="nation" kind="xsd:string"/>
              identify="inhabitants" kind="xsd:integer"/>
              identify="space" kind="xsd:integer"/>
              identify="elevation" kind="xsd:integer"/>
              identify="longitude" kind="xsd:decimal"/>
              identify="latitude" kind="xsd:decimal"/>
              identify="description" kind="xsd:string"/>
              identify="historical past" kind="xsd:string"/>

The tag signifies that the kid components should seem within the order, the sequence, specified right here.

Evaluate the pattern XML Schema and the pattern XML Doc – attempt to observe patterns within the code and the way the XML Schema units up the XML Doc.

3. Parts which have attributes are additionally designated as advanced kind.

a. this XML Doc line: class="state" identify="Cayo" />
can be outlined within the XML Schema as:

                identify="class" kind="xsd:string" />
                identify="identify" kind="xsd:string" />

b. this XML Doc line: class="state">Cayo
can be outlined within the XML Schema as:

                                 identify="class" kind="xsd:string" />

Attribute declarations[edit]

Attribute declarations are utilized in advanced kind definitions. We noticed some attribute declarations within the third instance of the Advanced Kind Ingredient.

 identify="class" kind="xsd:string" />

Knowledge kind declarations[edit]

These are contained inside aspect and attribute declarations as: kind=” ” .

Frequent XML Schema Knowledge Varieties

XML schema has quite a lot of built-in information varieties. The commonest varieties are:

string a string of characters
decimal a decimal quantity
integer an integer
boolean the values true or false or 1 or 0
date a date, the date sample will be specified similar to YYYY-MM-DD
time a time of day, the time sample will be specified similar to HH:MM:SS
dateTime a date and time mixture
anyURI if the aspect will include a URL

For a complete record of built-in easy information varieties see http://www.w3.org/TR/xmlschema-2/#built-in-datatypes

Utilizing an XML Editor => XML Editor

This hyperlink will take you to directions on the way to begin an XML editor. After you have adopted the steps to get began you’ll be able to copy the code within the pattern XML schema doc and paste it into the XML editor. Then verify your outcomes. Is the XML schema well-formed? Is the XML schema legitimate?

XML stylesheet (XSL)[edit]

An XML Stylesheet is an XML Doc. XML Stylesheets have an .xsl file extension.

The eXtensible Stylesheet Language (XSL) supplies a way to rework and format the contents of an XML doc for show. Since an XML doc doesn’t include tags a browser understands, similar to HTML tags, browsers can not current the info with out a stylesheet that incorporates the presentation info. By separating the info and the presentation logic, XSL permits folks to view the info in response to their completely different wants and preferences.

The XSL Transformation Language (XSLT) is used to remodel an XML doc from one type to a different, similar to creating an HTML doc to be considered in a browser. An XSLT stylesheet consists of a set of formatting directions that dictate how the contents of an XML doc will likely be displayed in a browser, with a lot the identical impact as Cascading Stylesheets (CSS) do for HTML. A number of views of the identical information will be created utilizing completely different stylesheets. The output of a stylesheet isn’t restricted to a browser.

In the course of the transformation course of, XSLT analyzes the XML doc and converts it right into a node tree – a hierarchical illustration of your complete XML doc. Every node represents a bit of the XML doc, similar to a component, attribute or some textual content content material. The XSL stylesheet incorporates predefined “templates” that include directions on what to do with the nodes. XSLT will use the match attribute to narrate XML aspect nodes to the templates, and remodel them into the ensuing doc.

Exhibit 7: XML stylesheet doc for metropolis entity

 model="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Rework">
                </span>Tour Information<span class="nt">


choose="tourGuide"/> match="tourGuide"> choose="metropolis">
Inhabitants: choose='format-number(inhabitants, "##,###,###")'/>

The output of the town.xsl stylesheet in Desk 2-Three will seem like the


Inhabitants: 3,128,600

Inhabitants: 18,880,000


You’ll discover that the stylesheet consists of HTML to tell the media device (an online browser) of the presentation design. If you don’t already know HTML this will appear a bit of complicated. On-line sources such because the W3Schools tutorials may also help with the essential understanding you’ll need =>(http://www.w3schools.com/html/default.asp).

Integrated throughout the HTML is the XML that provides the info, the data, contained inside our XML doc. The XML of the stylesheet signifies what info will likely be displayed and the way. So, the HTML constructs a show and the XML plugs in values inside that show. XSL is the device that transforms the data into presentational type, however on the similar time retains the which means of the info.

XML at Bertelsmann – a case examine

The German Bertelsmann Inc. is a privately owned media conglomerate working in 56 nations. It has pursuits in such companies as TV broadcast (RTL), journal (Gruner & Jahr), books (Random Home) and so forth. In 2005 its 89 000 workers generated 18 billion € of income.

A serious concern of such a diversified enterprise is using synergies. Administration wants to ensure the Random Home workers don´t spend money and time determining what RTL TV journalists have already got give you.

Thus information administration based mostly on IT guarantees enormous time financial savings. Consequently Bertelsmann in 2002 began a undertaking referred to as BeCom.
BeCom´s function was to allow the completely different Bertelsmann companies to make use of the identical information for his or her completely different media purposes.
XML is essential on this undertaking, as a result of it permits for separating information (doc) from presentation (model sheet). Thus information can each be examined statistically and be modified to suit completely different media like TV and newspapers.

Statistical XML information administration for instance allows workers to learn from CBR (Case Primarily based Reasoning). CBR permits a Bertelsmann worker who searches for particular content material to revenue from earlier search findings of different Bertelsmann workers, thus gaining information which is far more contextual than remoted analysis outcomes solely.
In addition to XML information administration, Bertelsmann TV and Guide items can apply this optimized information of their particular media utilizing a wide range of lay-out purposes like 3B2 or QuarkXPress.


  • the XML declaration;
  • the stylesheet declaration;
  • the namespace declaration;
  • the output doc format.
  model="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Rework">

The XML declaration


The stylesheet & namespace declarations

      model="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Rework">
  • identifies the doc as an XSL model sheet;
  • identifies the model quantity;
  • refers back to the W3C XSL namespace – the URL for the location that describes the XML components and information varieties used within the schema. You could find extra about namespaces right here => Namespace. Each time the xsl: prefix is used it references the given namespace.

The output doc format


This aspect designates the format of the output doc and should be a toddler aspect of


The aspect is used to create templates that describe the way to show components and their content material. Above, within the XSL introduction, we talked about that XSL breaks up the XML doc into nodes and works on particular person nodes. That is accomplished with templates. Every template inside an XSL describes a single node. To establish which node a given template is describing, use the ‘match’ attribute. The worth given to the ‘match’ attribute is known as a sample. Bear in mind: (node tree – a hierarchical illustration of your complete XML doc. Every node represents a bit of the XML doc, similar to a component, attribute or some textual content content material). Wherever there may be branching within the node tree, there’s a node. defines the beginning of a template and incorporates guidelines to use when a specified node is matched.

the match attribute


This template match attribute associates the XML doc root (/), the entire department of the XML supply doc, with the HTML doc root. Contained inside this template aspect is the everyday HTML markup discovered initially of any HTML doc. This HTML is written to the output. The XSL seems to be for the basis match after which outputs the HTML, which the browser understands.


This template match attribute associates the aspect ‘tourGuide’ with the show guidelines described inside this aspect.


Parts particular to XSL:

XSL Ingredient Which means
(from our pattern XSL)
Prints the precise textual content discovered between this aspect’s tags
This aspect is used with a ‘choose’ attribute to search for the worth of the node chosen and plug it into the output.
This aspect is used with a ‘choose’ attribute to deal with components that repeat by looping via all of the nodes within the chosen node set.
This aspect will apply a template to a node or nodes. If it makes use of a ‘choose’ attribute then the template will likely be utilized solely to the chosen baby node(s) and might specify the order of kid nodes. If no ‘choose’ attribute is used then the template will likely be utilized to the present node and all its baby nodes in addition to textual content nodes.

For extra XSL components => http://www.w3schools.com/xsl/xsl_w3celementref.asp .

Language-Particular Validation and Transformation Strategies[edit]

PHP Strategies of XML Dom Validation[edit]

Utilizing the DOM DocumentObjectModel to validate XML and with a DTD DocumentTypeDeclaration and the PHP language on a server and extra

Browser Strategies[edit]

Place this line of code in your .xml doc after the XML declaration (prologue).


PHP XML Manufacturing[edit]

 $xmlData = "";
 or die('Failed to connect with the DBMS');
 // make connection to database
 or die('Didn't open the requested database');
 $outcome = mysql_query('SELECT * from college students') or die('Question to love get the data failed');
 if (mysql_num_rows($outcome)<1){
    die ('');
 $xmlString = "n";
 $xmlString .= "t";
 whereas ($row = mysql_fetch_array($outcome)) {
         $xmlString .=  "
 $xmlString .= "n";
 $xmlString .= "";
 echo $xmlString;
 $myFile = "classList.xml"; //any file
 $fh = fopen($myFile, 'w') or die("cannot open file"); //create filehandler
 fwrite($fh, $xmlString); //write the info into the file
 fclose($fh); //ALL DONE!

PHP Strategies of XSLT Transformation[edit]

This one is sweet for PHP5 and wampserver (newest). Please be certain that *xsl* is NOT commented out in
the php.ini file.

 // Load the XML supply
 $xml = new DOMDocument;
 $xsl = new DOMDocument;
 // Configure the transformer
 $proc = new XSLTProcessor;
 $proc->importStyleSheet($xsl); // connect the xsl guidelines
 echo $proc->transformToXML($xml);

Instance 1, Utilizing inside PHP itself (use phpInfo() perform to verify XSLT extension; allow if wanted)
This instance may produce XHTML. Please be aware it might produce something outlined by the XSL.

 $xhtmlOutput = xslt_create();
 $args = array();
 $params = array('foo' => 'bar');
 $theResult = xslt_process(
 xslt_free($xhtmlOutput); // free that reminiscence
 // echo theResult or reserve it to a file or proceed processing (maybe directions)

Instance 2:

 if (PHP_VERSION >= 5) {
   // Emulate the outdated xslt library capabilities
   perform xslt_create() {
       return new XsltProcessor();
   perform xslt_process($xsltproc,
                          $xslcontainer = null,
                         $args = null,
                         $params = null) {
       // Begin with making ready the arguments
       $xml_arg = str_replace('arg:', '', $xml_arg);
       $xsl_arg = str_replace('arg:', '', $xsl_arg);
       // Create cases of the DomDocument class
       $xml = new DomDocument;
       $xsl = new DomDocument;
       // Load the xml doc and the xsl template
       // Load the xsl template
       // Set parameters when outlined
       if ($params) {
           foreach ($params as $param => $worth) {
               $xsltproc->setParameter("", $param, $worth);
       // Begin the transformation
       $processed = $xsltproc->transformToXML($xml);
       // Put the lead to a file when specified
       if ($xslcontainer) {
           return @file_put_contents($xslcontainer, $processed);
       } else {
           return $processed;
   perform xslt_free($xsltproc) {
 $arguments = array(
   '/_xml' => file_get_contents("xml_files/201945.xml"),
   '/_xsl' => file_get_contents("xml_files/convertToSql_new2.xsl")
 $xsltproc = xslt_create();
 $html = xslt_process(
 print $html;

PHP file writing code[edit]

 $myFile = "testFile.xml"; //any file
 $fh = fopen($myFile, 'w') or die("cannot open file"); //create filehandler
 $stringData = "ntnthowdyn"; // get a string prepared to write down
 fwrite($fh, $stringData); //write the info into the file
 $stringData2 = "tn";
 fwrite($fh, $stringData2); //write extra information into the file
 fclose($fh); //ALL DONE!

XML Colours[edit]

To be used in your stylesheet: these colours can be utilized for each background and font




Utilizing an XML Editor => XML Editor

This hyperlink will take you to directions on the way to begin an XML editor. After you have adopted the steps to get began you’ll be able to copy the code within the pattern XML stylesheet doc and paste it into the XML editor. Then verify your outcomes. Is the XML stylesheet well-formed?

XML at Thomas Cook dinner – a case examine[edit]

Because the main journey firm and most widely known manufacturers on this planet, Thomas Cook dinner works throughout the journey worth chain – airways, resorts, tour operators, journey and incoming companies, offering its clients with the suitable product in all market segments throughout the globe. Using over 11,000 workers, the Group has 33 tour operators, round 3,600 journey companies, a fleet of 80 plane and a workforce numbering some 26,000. Thomas Cook dinner operates all through a community of 616 places in Europe and abroad. The corporate is now the second largest journey group in Europe and the third largest on this planet.

As Thomas Cook dinner sells different firms´ merchandise, starting from packaged holidays to automotive hires, it must recurrently change its on-line brochure. Earlier than Thomas Cook dinner began utilizing XML, it put info into HTML format, and would take upto six weeks to get an internet brochure up and operating on-line. XML helps do that job in about three days. This helps present all of Thomas Cook dinner´s present and potential clients and its varied companies in numerous geographical places with up to date info, as an alternative of getting to attend six weeks for brand new info to be launched.

XML permits Thomas Cook dinner to place content material info right into a single database, which will be re-used as many instances as required.
“We didn’t wish to maintain having to re-do the identical content material, we needed the power to modify it on instantly,” mentioned Gwyn Williams, who’s content material supervisor at Thomascook.com. “This has introduced inside advantages similar to with the ability to re-deploy workers into extra worth added areas.” Thomascook.com presently holds 65,000 pages of brochure and journey information info and an internet journal in XML format.

Thomas Cook dinner began utilizing XML at a comparatively early stage. As Thomas Cook dinner has a big database, the early use of XML will stand it in good stead. In some unspecified time in the future, the databases must be included into XML, and it’s reported that XML databases are faster than standard databases, giving Thomas Cook dinner a slight aggressive benefit towards those that don’t use XML.

Thomas Cook dinner has discovered that this will result in substantial price reductions in addition to consistency of data throughout all channels. By implementing a central content material administration system to facilitate brochure manufacturing and internet publications, they’ve centralized the manufacturing, upkeep and distribution of content material throughout their manufacturers and channels.


From the earlier chapter Introduction to XML, you might have discovered the necessity for information alternate and the usefulness of XML in information alternate. On this chapter, you might have discovered extra in regards to the three main XML recordsdata: the XML doc, the XML schema, and the XML stylesheet. You discovered the right documentation required for every kind of file. You discovered fundamental guidelines of syntax relevant for all XML paperwork. You discovered the way to combine the three kinds of XML paperwork. And also you discovered the definition and distinction between a well-formed doc and a legitimate doc. By following the XML Editor hyperlinks, you had been capable of see the outcomes of the pattern code and discover ways to use an XML Editor.

Beneath are Workout routines and Solutions for additional follow. Good Luck!

Dan Connelly
XML Declaration
father or mother
*Properly-formed XML

Train 1.

a)Utilizing “tourguide” above as a great instance, create an XML doc whose root is “classlist” . This CLASSLIST is created from a place to begin of single entity, STUDENT. Any variety of college students include components: firstname, lastname, emailaddress.