I'm using xslt to apply some templates on a xml file and output a html page. So I defined the method of 'xsl:output' as 'html'. However, I need to display some xml nodes from the xml file in their original format and unfortunately they didn't appear on the html page as I expected.
This is the sample xml file:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<employees>
<employee>
<name>Hello World</name>
<title>UI Designer</title>
</employee>
</employees>
My xslt is as follows:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html"/>
<xsl:template match="/">
<html>
<head>
<title>Example of Employee Data</title>
</head>
<body>
<h2>The following shows the structure of employee data file: </h2>
<div style="background-color: grey">
<xsl:copy-of select="employees/employee"/>
</div>
......
</body>
</html>
</xsl:template>
</xsl:stylesheet>
When I viewed the page source, the node 'employee' and its children were there, they were just not displayed in the html page. I think it's because I specified the output method as 'html'. But I have to generate a html page and embed some xml-format nodes into my page...
I've been trying but failing...Could anyone give me some help? Thanks!!
I expect the output page to be:
It's probably a bit late for that, but I ended up in this page looking for exactly the same thing.
A very simple way of copying XML data on your HTML page via XLST would be to use the frame. I've found this solution here, and apparently it is obsolete and deprecated, but I've just tested and it's working.
<xmp>
<xsl:copy-of select="."/>
</xmp>
As you can see from the screenshot, I've got a nice accordion with XML data below!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With