Web Developer's Virtual Library: Encyclopedia of Web Design Tutorials, Articles and Discussions


WDVL Newsletter

Active Server Pages
JSP/Java Servlets
Microsoft SQL Server
Daily Backup
Dedicated Servers
Streaming Audio/Video
24-hour Support    

jobs.webdeveloper.com

Hiermenus


e-commerce
Partner With Us















Developer Channel
FlashKit.com
JavaScript.com
JavaScriptSource
Developer Jobs
ScriptSearch
StreamingMediaWorld
Web Developer's Journal
Web Developer's Virtual Library
WebDeveloper.com
Webreference
Web Hosts
XMLfiles.com

internet.com
IT
Developer
Internet News
Small Business
Personal Technology

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers


Defining an XSL Rule

First, XSL styles are defined as elements with an element name of "rule" and containing patterns used to match a style with a specific XML element. For example, the following defines an XSL rule for an element with the label of "title", and applies a presentation equivalent to an H1 header, with a red font and using the font-family of "Arial":

<xsl>
 <rule>
   <target-element type="title"/>
	<H1 color="red" font-family="Arial">
	<children/>
	</H1>
  </rule>
</xsl>

This style rule has a target-element of "title", which means the rule will be applied to any XML element with a name of "title". The implied H1 element style is then applied to the "children" of the element. The children of the element is any content contained within the beginning and ending target element tags that is, itself, not another element. The H1 element style is amended to also include a font color of "red" and a font family of "Arial".

To test the XSL file, it and the test XML file are run through the Microsoft command line XSL processor, msxsl.exe, downloadable from a URL in the resource section. This processor does not implement all of the XSL specification, but does process enough to demonstrate how XSL and XML are combined to generate a document viewable by the 4.x Navigator and IE browsers.

The msxsl.exe utility is run against the XML and XSL test code using the following line:

msxsl -i test.xml -s test.xsl -o test1.htm

This command line runs the utility, passing in the XML input file, with the "-i" flag, the XSL style file, with the "-s" flag, and the output file, with the "-o" flag. The result of running the processing is the generated HTML:

<DIV><H1 style="color: red; font-family: Arial">
What is XML
</H1><H1 style="color: red; font-family: Arial">
What is a markup language
</H1> A markup language is any language that contains 
markup characters that determine how the contents are processed.
<H1 style="color: red; font-family: Arial">
What is XML?
</H1> XML is Extended Markup Language, a generic language used to 
generate documents without following predefined element types. </DIV>

You can actually check out the generated output. Note that the contents are placed within a DIV block, and the H1 header with the associated CSS style attribute is applied to each "title" element. The reason all three title elements are modified is because there is no constraint in the XSL rule that limits the style to the top level title or the title within the sidebar element. How to fine tune which elements receive which styles is covered in the next section.

What is XSL?
Add a little style to your XML document with XSL - a Working Example
Adding Parental Patterns to the XSL Rule


Up to => Home / Authoring / Languages / XSL / Example




Jupiter Online Media: internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and Jupiter Online Media

Jupitermedia Corporate Info


Legal Notices, Licensing, & Permissions, Privacy Policy.

Web Hosting | Newsletters | Tech Jobs | Shopping | E-mail Offers