Welcome to WebmasterWorld Guest from 54.145.176.120

Forum Moderators: httpwebwitch

Message Too Old, No Replies

paths in xsl

   
3:31 pm on May 19, 2009 (gmt 0)

5+ Year Member



I am fairly new to this but what I want to do is
put a path to an image somewhere in my xsl document so I can add a function to a javascript file to be able to get this path so the javascript file knows where to find the image.

Just to play around I also hardcoded the path in the Js file but the only way I could access the image was by something like this ../image and not with an absolute path like c:/output/image or c:\output\image

7:52 pm on May 19, 2009 (gmt 0)

WebmasterWorld Administrator httpwebwitch is a WebmasterWorld Top Contributor of All Time 10+ Year Member



There are many possible ways to do this. here's one:

In your XSL, you can create a <script> element and define a global variable in it.

[the following goes in your XSL, preferably inside the <head> or early in the <body>]

<script>
<xsl:text>window.myvariable = '</xsl:text>
<xsl:value-of select="xpath-to-your-image-name" />
<xsl:text>';</xsl:text>
</script>

Another way would be to hide the image name in the DOM, and use JavaScript to retrieve it

Another way would be to create an XML "Island" in the DOM, and parse data out of that

I'd go for the first method; it's easiest.

Good luck cjcj1!

1:00 pm on May 20, 2009 (gmt 0)

5+ Year Member



Thanks. So If I do it the first way you suggested, how would I then retrieve the value in JavaScript?

Thanks.

7:43 pm on May 20, 2009 (gmt 0)

5+ Year Member



I think you could do so with document object model, it's the way several programming languages, including Javascript, browse and retrieve info from XML files. Read on it.
12:52 am on May 21, 2009 (gmt 0)

WebmasterWorld Administrator httpwebwitch is a WebmasterWorld Top Contributor of All Time 10+ Year Member



>> how would I then retrieve the value in JavaScript

In the example above, your value is stored in a variable called "window.myvariable". Since "window" is the default root global scope, you can just use "myvariable", like this:

<script>
alert(myvariable);
</script>

2:20 pm on May 21, 2009 (gmt 0)

5+ Year Member



Great thanks!
 

Featured Threads

Hot Threads This Week

Hot Threads This Month