0 Replies - 386 Views - Last Post: 03 June 2013 - 07:29 AM

#1 Dillon10R  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 29-May 13

Links to Support Stylesheet Switching

Posted 03 June 2013 - 07:29 AM

Hello. I am making a simple XML-based website and styling it using XSLT. I am trying to incorporate the option for multiple stylesheets to be applied to a single XML document and give users the option to switch between stylesheets by clicking a link on a page. First of all, is this even possible? If it is, how would I go about making it happen?

This is what I have so far, but it does not seem to be working:

Here is the top of my single XML Page (called "Home.xml")
<?xml version="1.0"?>

<?xml-stylesheet alternate="no" type="text/xsl" title="main" href="Home.xsl"?>

<?xml-stylesheet alternate="yes" title="alternate" href="Home2.xsl"
type="text/xsl"?>
<home>
    ...<rest of the Home.xml page>...




Here is the top of my main XSL stylesheet (called "Home.xsl")
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
 	<head>
		<link href="Home2.xsl" rel="alternate stylesheet"
		type="text/xsl" title="alternate" media="screen" />
		
		<script type="text/Javascript">
			function changeStyle(title) {
			var lnks = document.getElementsByTagName('link');
			for (var i = lnks.length - 1; i >= 0; i--) {
			if (lnks[i].getAttribute('rel').indexOf('style')> -1 #&amp;#&amp; lnks[i].getAttribute('title')) {
			lnks[i].disabled = true;
			if (lnks[i].getAttribute('title') == title) lnks[i].disabled = false;
			}}}
		</script>
 	</head>
        <body>



... And further down on the Home.xsl page, I included the following code in attempt to switch the stylesheets by clicking on a link.
<a href="Home.xml"><span onclick="changeStyle('alternate')"><xsl:value-of select="percent"/></span></a><br/><br/>




If I could get some help with this, that would be fantastic.

Is This A Good Question/Topic? 0
  • +

Page 1 of 1