homepage Welcome to WebmasterWorld Guest from 54.211.230.186
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / XML Development
Forum Library, Charter, Moderators: httpwebwitch

XML Development Forum

    
paths in xsl
cjcj1

5+ Year Member



 
Msg#: 3916512 posted 3:31 pm on May 19, 2009 (gmt 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

 

httpwebwitch

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



 
Msg#: 3916512 posted 7:52 pm on May 19, 2009 (gmt 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!

cjcj1

5+ Year Member



 
Msg#: 3916512 posted 1:00 pm on May 20, 2009 (gmt 0)

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

Thanks.

kaidok

5+ Year Member



 
Msg#: 3916512 posted 7:43 pm on May 20, 2009 (gmt 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.

httpwebwitch

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



 
Msg#: 3916512 posted 12:52 am on May 21, 2009 (gmt 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>

cjcj1

5+ Year Member



 
Msg#: 3916512 posted 2:20 pm on May 21, 2009 (gmt 0)

Great thanks!

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / XML Development
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved