Rules XSL


The XSL-document represents set of rules of construction, each of which is selected in the separate block limited to tags <rule> and </rule>;. Rules define{determine} patterns on which to each element XML the sequence of HTML-tags is put in conformity, i.e. inside them the instructions determining elements of the XML-document and tags of formatting, used to them contain.


Elements XML to which formatting will be applied, are designated in XSL by a descriptor <target-element/>;. For the instruction{indication} of an element with the concrete name (the name of an element is defined{determined} by tags, his{its} designating), i.e. definitions of a class of an element, it is possible to use attribute type = "<imja_ehlementa>"


Example of the elementary XSL-document determining formatting for a fragment <flower> rose </flower>:



<xsl>

<rule>

<target-element type = "flower"/>

<p color = "red" font-size = "12">

<children/>

</p>

</rule>

</xsl>


Already on this example it is possible to track feature of use of style tables: in any rules by means of corresponding elements deklarativno the area which defines{determines} a fragment of the XML-document as we hardly shall see later is set, the program - analyzer anew passes all elements, since current, every time when in structure of the XML-document the new enclosed elements are found out.


The instruction <target-element> specifies that the given rule defines{determines} an element. The parameter type = "flower" sets the name of a XML-element for which this rule will be used. The program - converter will use the HTML-tags placed inside the block <rule> </rule> for formatting of a XML-element to which the current block "intended". In the event that for any element XML the pattern is not defined{determined}, in the target document tags of formatting by default (for example, <DIV> </DIV>) will be added


Process of analysis of XSL-rules is recursive i.e. if the element has affiliated elements the program will search for definitions of these elements located "more deeply" in a tree of the document. The instruction{indication} that it is necessary to repeat process of analysis XML of the document, already for affiliated elements, is the instruction <children/>. Dojdja up to it{her}, the analyzer will choose the necessary branch from a hierarchical tree of XML-elements and will find the rules determining formatting of these underlaying elements in XSL-patterns. In the event that instead of <children> we shall specify the instruction <empty/>;, the program will finish movement on the given branch and will come back back, in a parental rule. Thus the current rule of any information in the target HTML-document will not change, since <empty/> in this case means, that contents of an element are absent.


If in one rule <target-element> it is used some times instructions on formatting will be distributed on all XML-elements described inside him{it}, i.e. it is possible to set a uniform pattern of formatting for several elements simultaneously:



<xsl>

<rule>

<target-element type = "item1"/>

<target-element type = "item2"/>

<target-element type = "item3"/>

<hr>

<children/>

<hr>

</rule>

</xsl>


The example of more complex{difficult} XSL-description which some fragments will be explained later is below resulted.


The XML-document:



<? XML Version = " 1.0"?>

<documents>

<books>

<book id = "Book1">

<title> Makroehnomicheskie parameters of economy

Roman empire during its{her} blossoming </title>

<author> Ivan Petrov </author>

<date> 21.08.98 </date>

</book>

<book id = "Book2">

<title> Floriculture and animal industries.

Practical advice{councils} </title>

<author> Peter Sidorov </author>

<date> 10.10.98 </date>

</book>

</books>

<articles>

<article id = "Article1">

<author> Peter Ivanov </author>

<title> Influence of increase of tariffs of payment for phone

On life expectancy of the population </title>

<date> 12.09.98 </date>

</article>

</articles>

</documents>


Contents of the XSL-document:



<xsl>

<rule>

<root/>

<HTML>

<BODY bgcolor = "white">

<center> <hr width = " 80 % "/> <b> Library </b>

        <hr width = " 80 % "/> <br/>

<table width = " 80 % " border = "2">

<children/>

</table> </center>

</BODY>

</HTML>        

</rule>

<rule>

         <element type = "book">

         <target-element type = "author"/>

</element>

<td align = "center">

         <p color = "red" font-size = "14"> <b>

<children/>

</b> </p> </td>

</rule>

<rule>

         <element type = "article">

         <target-element type = "author"/>

</element>

<td align = "center">

         <p color = "red" font-size = "14"

font-style = "italic"> <children/> </p> </td>

</rule>

<rule>

         <target-element type = "book"/>

<tr> <children/> </tr>

</rule>

<rule>

         <target-element type = "article"/>

<tr> <children/> </tr>

</rule>

<rule>

         <target-element/>

<td align = "center"> <p> <children/> </p> </td>

</rule>

<rule>

         <target-element type = "books"/>

<tr> <td colspan = "3" bgcolor = "silver"

> Books </td> </tr>

<children/>

</rule>

<rule>

         <target-element type = "articles"/>

<tr> <td colspan = "3" bgcolor = "silver"

> Articles </td> </tr>

<children/>

</rule>

</xsl>



Root rule


Analysis of any XSL-document always begins with a rule for a root element in which the area of all razbiraemogo XML the document and consequently the tags of formatting placed here is defined{determined}, will act on the document as a whole. For a designation of a root rule it is necessary to switch on in him{it} an element <root/>;. For example, to set a tag <body> for target HTML-page formed by us, we can use the following fragment:



<xsl>

<rule>

<root/>

<html> <head> <title> Flowers </title> </head>

<body bgcolor = "white" link = "blue" alink = "darkblue"

vlink = "darckblue">

<children/>

</body>

</html>

</rule>

</xsl>


In this example by means of instructions <root/> and <children/> we have defined{determined} a number{line} of initial and final HTML-tags for our page between which then during recursive detour of the XSL-analyzer the others will be placed an element of the document.


In the event that we do not determine a rule for a root element, analysis of the document will begin from the first rule with the instruction <target-element> (for registration of heading of the document the sample of formatting used by default) will be used.