1 <?php
2 /**
3 * XAO_DomXsl.php
4 *
5 * This script facilitates programatic creation of XSLT templates.
6 * This may be used to dynamically generate the GUI at runtime. For whatever
7 * reason, the display logic may benefit from this dynamism over selecting from
8 * a list of different stylesheet. This is a very advanced feature and is not
9 * intended for use by casual users.
10 */
11
12 /**
13 * Import the basic DomDoc class for inheritance.
14 *
15 * This class is based on DomDoc and hence supports all of it's functionality,
16 * including it's ability to be consumed by another DomDoc based object.
17 *
18 * @import DomDoc
19 */
20 include_once "XAO_DomDoc.php";
21
22 /**
23 * XSL Stylesheet as a DomDoc object
24 *
25 * WARNING - WARNING - WARNING - WARNING - WARNING - WARNING - WARNING
26 * DO NOT ATTEMPT TO USE THIS CLASS. IT IS A WORK IN PROGRESS. IT IS VAPOURWARE.
27 * IT PROBABLY HAS NOT EVEN BEEN THROUGH THE INTERPRETER/PARSER YET. IT WILL NOT
28 * WORK. THE DESIGN WILL CHANGE. THERE'S STILL MUCH WORK TO BE DONE. LEAVE IT.
29 * This class inherits from DomDoc. It is used to create and manipulate
30 * stylesheets programatically.
31 *
32 * @author Terence Kearns
33 * @version 0.2
34 * @copyright Terence Kearns 2003
35 * @license LGPL
36 * @package XAO
37 * @link http://xao-php.sourceforge.net
38 */
39 class DomXsl extends DomDoc {
40
41 /**
42 * Whether or not the stylesheet is valid.
43 *
44 * This is set using $this->blnValidate which is only run in the constructor
45 * and only when an existing stylesheet is passed to the constructor.
46 * Otherwise, it is assumed to be true since the alternative is that we
47 * initialised a valid stylesheet in the constructor.
48 * This variable is checked for trueness every time a utility function is
49 * called. If the function finds that this var is not set to true, then it
50 * will do nothing and return false.
51 *
52 * @access public
53 * @var bool
54 */
55 var $blnValid = true;
56
57 var $idXslNs = "http://www.w3.org/1999/XSL/Transform";
58
59 var $strPrefix = "xsl:";
60
61 function DomXsl($uriExternal = null) {
62 // This check is performed in case the
63 // user overrides $this->strPrefix
64 // incorrectly.
65 if(strlen($this->strPrefix) && substr($this->strPrefix,-1) != ":") {
66 $this->Throw(
67 "DomXsl: The stylesheet namespace prefix must end with "
68 ."a colon.", $this->arrSetErrFnc(__FUNCTION__,__LINE__)
69 );
70 $this->blnValid = false;
71 return;
72 }
73 if(strlen($uriExternal)) {
74 $this->DomDoc($uriExternal,XAO_DOC_REFERENCE);
75 if(!$this->blnValid = $this->blnValidate()) $this->Throw(
76 "DomXsl: Stylesheet specified (".$uriExternal
77 .") is not valid.",
78 $this->arrSetErrFnc(__FUNCTION__,__LINE__)
79 );
80 }
81 else {
82 $this->DomDoc("stylesheet");
83 $strPr = "";
84 if(substr($this->strPrefix,-1) == ":")
85 $strPr = substr($this->strPrefix,0,-1);
86 $this->ndRoot->set_namespace($this->idXslNs,$strPr);
87 $this->ndRoot->set_attribute("version","1.0");
88 }
89 }
90
91 function &ndMkTpl($arrAtts) {
92 if(count($arrAtts)) {
93 $ndTpl = $this->ndAppendToRoot($this->strPrefix."template");
94 $this->Arr2Atts($ndTpl,$arrAtts);
95 return $ndTpl;
96 }
97 else {
98 $this->Throw(
99 "ndMkTpl: You must either specify a MATCH or a NAME "
100 ."attribute",
101 $this->arrSetErrFnc(__FUNCTION__,__LINE__)
102 );
103 }
104 return false;
105 }
106
107 function blnValidate() {
108 $arrNsAtt = array();
109 $strVer = "";
110 $arrAtts =& $this->ndRoot->attributes();
111 foreach($arrAtts AS $ndAtt) {
112 if($ndAtt->value == $this->idXslNs) {
113 $arrNsAtt = explode(":",$ndAtt->name);
114 if(isset($arrNsAtt[1])) $this->strPrefix = $arrNsAtt[1].":";
115 }
116 if($ndAtt->name == "version") $strVer = $ndAtt->value;
117 }
118 if(!count($arrNsAtt)) return false;
119 if($strVer != "1.0") return false;
120 return true;
121 }
122 }
123
124 ?>