RU beehive logo ITEC dept promo banner
ITEC 325
2012fall
ibarland

homelectsexamshws
D2Lbreeze (snow day)

lect13a
XSLT, cont.
generating attributes; templates


One data file, many pages

Similar to how a web-page (data) can have a css-stylesheet directive (processing), XML data files have a xml-stylesheet tag, with what XSLT file processes them.

It's annoying, that the xml-stylesheet processing instruction should be in the same file as the raw XML data. What if you have one data file, and you want to use it to produce several different views/results? Alas, the usual solution is to fall back to a different technology: Have a php file which prints the xml-stylesheet line, and then require's the XML file:

// The file children.php:
<?xml-stylesheet type="text/xsl" href="children.xsl"?>
<?php
  require('children-data.xml');
?>
In fact, this might happen often enough that you choose to write a php util function — say, renderXMLWith([string] $xmlDataFile, [string] $xslTransformFile ) — which prints out these lines. (So the file being linked to (children.php) actually contains just two lines: requiring utils.php, and then a call to renderXMLWith).


1 In php it's no problem to have an expression whose result was inserted into the middle of an attribute. However, since XSLT is itself written in XML, and XML of course doesn't allow opening a tag in the middle of an attribute, the syntax physically precludes putting xls:select (etc.) expressions in the middle of an attribute.      

homelectsexamshws
D2Lbreeze (snow day)


©2012, Ian Barland, Radford University
Last modified 2012.Nov.28 (Wed)
Please mail any suggestions
(incl. typos, broken links)
to ibarlandradford.edu
Powered by PLT Scheme