XML
XML is used to transport data. HTML is used to format and display it.
if you have an XML file with data on music albums then you can call it up and view it like this:
simplexml_load_file()
Bob Dylan
Mar 1962
The Freewheelin' Bob Dylan
May 1963
The Times They Are a-Changin'
Jan 1964
Another Side of Bob Dylan
Aug 1964
Bringing It All Back Home
Mar 1965
Highway 61 Revisited
Aug 1965
Blonde on Blonde
Jun 1966
foreach
website-design/xml/simple/ -- simplexml_load_file
foreach($xmld->children() as $child) {
echo $child->title ."<br>";
}
catalog.xml
view the data return using the keyboard shortcut: Alt + Left arrow.
XSLT
XSLT is the style sheet language for XML files. XSLT transforms each XML element into an XHTML element.
the XSLT processor is doing most of the work. We apply templates at each level of the document, which moves the processing along to the children of the context node. There is no need to explicitly loop over any elements or output any text, due to XSLT's built-in templates. Then, we handle each table section in its own template. This is a flexible, maintainable, and readable approach.
catalog.xsl
<xsl:template match="album/*">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="release">
<xsl:value-of select="."/>
</xsl:template>
XPath
XPath uses path expressions to select nodes in an XML document.
The select attribute contains an XPath expression. The (.) selects the current node. An XPath expression works like navigating a file system; a forward slash (/) selects subdirectories.
cake.xml
<cake>
<layer flavor="vanilla">
cake.xsl
here we define the flavor attribute
cake/layer@flavor
vanilla