Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Applying one or more XSL -stylesheets to XML on client side

Status
Not open for further replies.

comma

Programmer
Feb 12, 2003
24
FI
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
 
Problem solved or at least one method was found.

I added a stylesheet href to the beginning of document, which is default stylesheet (<?xml-stylesheet href="default_style.xsl" type="text/xsl"?>) and then I made second XML -file, which contains only stylesheet definition to extra stylesheet and then I made templates to that stylesheet which uses document() function to access the main XML-file displaying it differently.

Also the main file contains link to the another XML-file (and therefore to different stylesheet).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top