Hi,
I was wondering, is there a good and easy method for applying two or more XSL-stylesheets to XML on client side? For example in XML formatted phonebook the contents would be reprsented in nicely formatted and coloured xHTML in first XSL and in plain text on the second XSL.
I have tried the following (these are just short examples, with no any "real" data to show the idea):
test_page.xml:
<?xml version="1.0" encoding="ISO-8859-1" standalone="no"?>
<report>
<testset name="Set 1">
<testcase name="testcase 1">
<result array="results2">
<arraydata>
<TABLE border="1">
<TR>
<TD>testing2</TD>
<TD>testing22</TD>
</TR>
<TR>
<TD>value2</TD>
<TD>value22</TD>
</TR>
</TABLE>
</arraydata>
</result>
</testcase>
</testset>
</report>
test.xsl:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="
<xsl:template match="/">
<html>
<b>Test stylesheet</b>
<xsl:apply-templates/>
</html>
</xsl:template>
<xsl:template match="arraydata">
<xsl:copy-of select="."/>
</xsl:template>
</xsl:stylesheet>
result_page.htm:
<html>
<body>
<script type="text/javascript">
// Load XML
var xml = new ActiveXObject("Microsoft.XMLDOM")
xml.async = false
xml.load("test_page.xml")
// Load XSL
var xsl = new ActiveXObject("Microsoft.XMLDOM")
xsl.async = false
xsl.load("test.xsl")
// Transform
document.write(xml.transformNode(xsl))
</script>
</body>
</html>
The problem with the script in result_page.htm is that it does not show anything. In the browser (IE) the XSL is show correctly if stylesheet inclusion definition is added to test_page.xml.
So I was wondering how to use two stylesheets and apply them dynamically on client side, e.g. clicking hyperlink, so that it would transform just like with the browser.
The bigger stylesheet would contain also some javascript to enable tabbing (or folders) to the resulting xHTML. So is it possible to do the stylesheet switching easily?
I have browsed the net very much, but have not found a good way to do this, so any help or hint would be appreciated.
br, comma
I was wondering, is there a good and easy method for applying two or more XSL-stylesheets to XML on client side? For example in XML formatted phonebook the contents would be reprsented in nicely formatted and coloured xHTML in first XSL and in plain text on the second XSL.
I have tried the following (these are just short examples, with no any "real" data to show the idea):
test_page.xml:
<?xml version="1.0" encoding="ISO-8859-1" standalone="no"?>
<report>
<testset name="Set 1">
<testcase name="testcase 1">
<result array="results2">
<arraydata>
<TABLE border="1">
<TR>
<TD>testing2</TD>
<TD>testing22</TD>
</TR>
<TR>
<TD>value2</TD>
<TD>value22</TD>
</TR>
</TABLE>
</arraydata>
</result>
</testcase>
</testset>
</report>
test.xsl:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="
<xsl:template match="/">
<html>
<b>Test stylesheet</b>
<xsl:apply-templates/>
</html>
</xsl:template>
<xsl:template match="arraydata">
<xsl:copy-of select="."/>
</xsl:template>
</xsl:stylesheet>
result_page.htm:
<html>
<body>
<script type="text/javascript">
// Load XML
var xml = new ActiveXObject("Microsoft.XMLDOM")
xml.async = false
xml.load("test_page.xml")
// Load XSL
var xsl = new ActiveXObject("Microsoft.XMLDOM")
xsl.async = false
xsl.load("test.xsl")
// Transform
document.write(xml.transformNode(xsl))
</script>
</body>
</html>
The problem with the script in result_page.htm is that it does not show anything. In the browser (IE) the XSL is show correctly if stylesheet inclusion definition is added to test_page.xml.
So I was wondering how to use two stylesheets and apply them dynamically on client side, e.g. clicking hyperlink, so that it would transform just like with the browser.
The bigger stylesheet would contain also some javascript to enable tabbing (or folders) to the resulting xHTML. So is it possible to do the stylesheet switching easily?
I have browsed the net very much, but have not found a good way to do this, so any help or hint would be appreciated.
br, comma