Is it possible to put XSL instructions inside JavaScript?

M

Matt

Is it possible to put XSL instructions inside JavaScript?
For example, pop up a message box with the xml value: alert(value in xml);

Approach #1:
<script type="text/javascript">
alert(<xsl:value-of select="@id"/>);
</script>

It will have javascript errors

Approach #2:

<xsl:text>&lt;script type="text/javascript"&gt;</xsl:text>
<xsl:text>alert(</xsl:text>
<xsl:value-of select="@id"/><xsl:text>)</xsl:text>
<xsl:text>&lt;/script&gt;</xsl:text>

If I try the following, it will display the javascript as text,
not the javascript message box in browser.

any ideas?? thanks!!
 
D

David Carlisle

Is it possible to put XSL instructions inside JavaScript?

The answer to that question would be a question about javascript but you
appear to be writing XSLT. (The actual character data being written by
xslt might be javascript, but XSLT doesn't care about that, it could
just as well be english or french.
For example, pop up a message box with the xml value: alert(value in xml);

Approach #1:
<script type="text/javascript">
alert(<xsl:value-of select="@id"/>);
</script>

This is the correct xslt syntax, once xslt has run the output will be
<script type="text/javascript">
alert(something);
</script>
which if passed to an html browswer will take the content of the script
and pass it to the javascript engine.depending what your javascript is
doing you might want
alert("<xsl:value-of select="@id"/>");
so you end up with
alert("something");
It will have javascript errors

Approach #2:

<xsl:text>&lt;script type="text/javascript"&gt;</xsl:text>
<xsl:text>alert(</xsl:text>
<xsl:value-of select="@id"/><xsl:text>)</xsl:text>
<xsl:text>&lt;/script&gt;</xsl:text>

If I try the following, it will display the javascript as text,
not the javascript message box in browser.

Using &lt; quotes the < specifically so that it is taken as text not markup.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top