In order for a parser to know what XML document goes with what XSLT style sheet, you must include directions in the XML code to connect the two files. XSLT identifies itself as an XSL style sheet with XSLT coding in the declaration statement, but does not give the address of the XML document that stores the data. The linking is done in the XML document.
XSLT Declaration
XSLT is an XSL style sheet that utilizes predefined elements to produce an output stream that displays information stored in XML. By incorporating the namespace information in the declaration statement, you point out to the processor that the XSL style sheet is transforming XML code to a mark up language, such as HTML or XHTML.
<?xml version= "1.0"?>
<xsl:stylesheet version= "1.0"
xmlns:xsl= "http://www.w3.org/1999/XSL/Transform">
This declaration statement sits at the top of all XSLT files. It points out that the language used is XML. The format applied is XSL or style sheet and the namespace URI http://www.w3.org/1999/XSL/Transform identifies it as a transformation document or XSLT.
XML Declaration
To connect the data in the XML file to the corresponding XSLT style sheet, you add a line in the declaration statement on the original XML document that links the two files.
<?xml version= "1.0"?>
<?xsl-stylesheet type= "text/xsl" href= "name of the XSLT style sheet"?>
The first line identifies the language of the file as XML. The following statement attaches a style sheet to the XML document. When the processor looks at the declaration statement, it understands an additional file exists with display instructions.
Keeping It Consistent
An internet browser does not care what you name your XSLT style sheet. It only cares that the file name is established in the XML code of the data file. The savvy programmer knows that connecting the names will help keep files organized and create a streamlined system. It is not required, but an excellent idea to use the same name for both files.
XML - myxml.xml
XSLT -myxml.xsl
Using the name as a reference point will keep your files together and the confusion to a minimum.
