PDA

View Full Version : Javascript defined XML variables!


MRMAN
05-30-2006, 03:11 PM
Hello.
I am trying to make a site that uses a xml feed. But instead of having one xml, xsl and css for every user i want to user JavaScript to pull the username from the url query string and user the style.css in the correct folder.

this is what i have and this works.

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output encoding="utf-8" method="html" />
<xsl:template match="/">
<html lang="en" xml:lang="en">
<head>
<script language="javascript" type="text/javascript">
test = location.search;
test2 = test.substring(1);
var temp = new Array();
temp = test2.split("&amp;");
var i = 0;
for(x in temp)
{
fonzie = temp[x]
start = new Array()
start = fonzie.split("=")
if(start[0] == 'affid')
{
alert('<link rel="stylesheet" type="text/css" href="'+start[1]+'/style.css" />')
document.write('<link rel="stylesheet" type="text/css" href="'+start[1]+'/style.css" />')
}
}
</script></head><body>


OK like i said that bit work. the next thing i want to do is to create a variable, again from the query string, that can be used in the rest of the xml. This is what i have

<script language="javascript" type="text/javascript">

test = location.search;
test2 = test.substring(1);
var temp = new Array();
temp = test2.split("&amp;");
var i = 0;
for(x in temp)
{
fonzie = temp[x]
start = new Array()
start = fonzie.split("=")
if(start[0] == 'affid')
{
document.write('<xsl:variable name="affid">1234</xsl:variable>')
}
if(start[0] == 'fimsid')
{
alert('<xsl:variable name="fimsid">431</xsl:variable>')
document.write('<xsl:variable name="fimsid">431</xsl:variable>')
}
}
</script>

and this is the code i am using so put the variable onto the screen
<tr onmouseover="this.className='selectionrowover'" onmouseout="this.className='selectionrow'" class="selectionrow" onclick="document.location='http://www.google.com/betslip/betsliplanding.asp?selid={@id}&amp;price={@price}&amp;fimsId={$fimsid}&amp;affid={$affid}'">

Please note that this is almost exactly the same code as above.

But if i have the second and third parts in the xsl file i get the error saying "Error during XSLT transformation: (null)"
This i assume is because the variables have not been defined.

Anyone got and clue what i need to do.

Cheers
MRMAN

MRMAN
05-30-2006, 03:27 PM
ok i have tried something else but i still get the same error.
this is what i have now

<msxsl:script language="javascript"
implements-prefix="foo">
function affiddata(){
test = location.search;
test2 = test.substring(1);
var temp = new Array();
temp = test2.split("&amp;");
var i = 0;
for(x in temp)
{

fonzie = temp[x]

start = new Array()
start = fonzie.split("=")



if(start[0] == 'affid')
{
return start[1];
}
}
}

function fimsiddata()
{
test = location.search;
test2 = test.substring(1);
var temp = new Array();
temp = test2.split("&amp;");
var i = 0;
for(x in temp)
{

fonzie = temp[x]

start = new Array()
start = fonzie.split("=")

if(start[0] == 'fimsid')
{

return start[1];

}
}
}

</msxsl:script>

<xsl:variable name="affid" select="foo:affiddata()" />
<xsl:variable name="fimsid" select="foo:fimsiddata()" />