Welcome to WebmasterWorld Guest from 54.225.20.19

Forum Moderators: open

Message Too Old, No Replies

paths in xsl

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

New User

5+ Year Member

joined:Apr 9, 2009
posts: 4
votes: 0


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)

Senior Member from CA 

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

joined:Aug 29, 2003
posts:4061
votes: 0


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)

New User

5+ Year Member

joined:Apr 9, 2009
posts:4
votes: 0


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)

New User

5+ Year Member

joined:May 13, 2009
posts:23
votes: 0


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)

Senior Member from CA 

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

joined:Aug 29, 2003
posts:4061
votes: 0


>> 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)

New User

5+ Year Member

joined:Apr 9, 2009
posts:4
votes: 0


Great thanks!