1 | <?php |
||
16 | abstract class AbstractNormalization |
||
17 | { |
||
18 | /** |
||
19 | * XSL namespace |
||
20 | */ |
||
21 | const XMLNS_XSL = 'http://www.w3.org/1999/XSL/Transform'; |
||
22 | |||
23 | /** |
||
24 | * @var bool Whether this normalization should be applied only once per template |
||
25 | */ |
||
26 | public $onlyOnce = false; |
||
27 | |||
28 | /** |
||
29 | * @var DOMDocument Document that holds the template being normalized |
||
30 | */ |
||
31 | protected $ownerDocument; |
||
32 | |||
33 | /** |
||
34 | * @var string[] XPath queries used to retrieve nodes of interest |
||
35 | */ |
||
36 | protected $queries = []; |
||
37 | |||
38 | /** |
||
39 | * @var DOMXPath |
||
40 | */ |
||
41 | protected $xpath; |
||
42 | |||
43 | /** |
||
44 | * Apply this normalization rule to given template |
||
45 | * |
||
46 | * @param DOMElement $template <xsl:template/> node |
||
47 | * @return void |
||
48 | */ |
||
49 | public function normalize(DOMElement $template) |
||
58 | |||
59 | /** |
||
60 | * Create an element in current template |
||
61 | * |
||
62 | * @param string $nodeName |
||
63 | * @param string $textContent |
||
64 | * @return DOMElement |
||
65 | */ |
||
66 | protected function createElement($nodeName, $textContent = '') |
||
79 | |||
80 | /** |
||
81 | * Create a text node in current template |
||
82 | * |
||
83 | * @param string $content |
||
84 | * @return DOMText |
||
85 | */ |
||
86 | protected function createTextNode($content) |
||
90 | |||
91 | /** |
||
92 | * Query and return a list of nodes of interest |
||
93 | * |
||
94 | * @return DOMNode[] |
||
95 | */ |
||
96 | protected function getNodes() |
||
102 | |||
103 | /** |
||
104 | * Test whether given node is an XSL element |
||
105 | * |
||
106 | * @param DOMNode $node |
||
107 | * @param string $localName |
||
108 | * @return bool |
||
109 | */ |
||
110 | protected function isXsl(DOMNode $node, $localName = null) |
||
114 | |||
115 | /** |
||
116 | * Make an ASCII string lowercase |
||
117 | * |
||
118 | * @param string $str Original string |
||
119 | * @return string Lowercased string |
||
120 | */ |
||
121 | protected function lowercase($str) |
||
125 | |||
126 | /** |
||
127 | * Normalize given attribute |
||
128 | * |
||
129 | * @param DOMAttr $attribute |
||
130 | * @return void |
||
131 | */ |
||
132 | protected function normalizeAttribute(DOMAttr $attribute) |
||
135 | |||
136 | /** |
||
137 | * Normalize given element |
||
138 | * |
||
139 | * @param DOMElement $element |
||
140 | * @return void |
||
141 | */ |
||
142 | protected function normalizeElement(DOMElement $element) |
||
145 | |||
146 | /** |
||
147 | * Normalize given node |
||
148 | * |
||
149 | * @param DOMNode $node |
||
150 | * @return void |
||
151 | */ |
||
152 | protected function normalizeNode(DOMNode $node) |
||
168 | |||
169 | /** |
||
170 | * Evaluate given XPath expression |
||
171 | * |
||
172 | * For convenience, $XSL is replaced with the XSL namespace URI as a string |
||
173 | * |
||
174 | * @param string $query XPath query |
||
175 | * @param DOMNode $node Context node |
||
176 | * @return DOMNodeList |
||
177 | */ |
||
178 | protected function xpath($query, DOMNode $node = null) |
||
184 | } |