| PHP5 and XSLT |
| Article Index |
|---|
| PHP5 and XSLT |
| Page 2 |
| Page 3 |
-
Lines 1 and 25 begin and end the PHP script and should at this point need little further explanation.
-
Lines 3 and 4 create and define variables to hold the names of the input XML file and the XSLT stylesheet, respectively.
-
Lines 6 and 7 create new DomDocument objects, capable of holding and manipulating well-formed XML documents (including XHTML and XSLT documents, which are also generally well-formed XML documents). These will be used to hold the XML input file and the XSLT stylesheet, respectively.
-
Line 9 calls the load() property of the $xml_obj DomDocument object to load the XML file given by the $path_xml variable defined in line 3.
-
Lines 10 and 11 display an error message and end execution if for some reason the XML input file can't be loaded or processed.
-
Line 14 calls the load() property of the $xsl_obj DomDocument object to load the XSLT file given by the $path_style variable defined in line 4.
-
Lines 15 and 16 display an error message and end execution if for some reason the XSLT input file can't be loaded or processed.
-
Line 19 creates a new XSLT processor resource at $xslt_parse, which can then be used for XSLT transformations.
-
Line 21 calls the importStyleSheet() property of the $xslt_parse resource to parse the XML document stored in $xsl_obj as an XSLT stylesheet in particular.
-
Line 23 calls the transformToXML() property of the $xslt_parse resource to apply the parsed XSLT stylesheet to the XML tree in $xml_obj; because the transformToXML() property returns a string in this case (the transformed HTML document), the echo command has been called to output this string to the Web browser.
Again, using other PHP skills you have already acquired, you should be able to incorporate these tools easily into more complex scripts.
| Users' Comments (0) |
|
No comment posted









