It doesn't work for two reasons. First, the window.location is in a comment in your xslt... so it isn't output. In order to get the comment characters to display in the output rather than be treated as comments in the xslt code itself you would need to use <xsl:text> statements.
Secondly, the use of {} to expand a value is only for inside tag attributes, such as the href="" of an achor tag. It isn't simply that you are inside quote marks; it must be a tag's attribute. Therefore, you need to use an xsl:value-of statement. But, since you're already inside double quotes you either need to use single quotes in the value-of, or break the line up with more xsl:text statements.
Here are some examples (I only tested the first one but the other should be correct even though I typed them in the forum editor):
window.location question
Hi,
I have one question.
This link works: <a href="{umbraco.library:NiceUrl($test/@id)}"></a>
If I replace the link above with
<script type="text/javascript">
<!--
window.location = "{umbraco.library:NiceUrl($test/@id)}"
//-->
</script>
it does not work.
What do I do wrong?
It doesn't work for two reasons. First, the window.location is in a comment in your xslt... so it isn't output. In order to get the comment characters to display in the output rather than be treated as comments in the xslt code itself you would need to use <xsl:text> statements.
Secondly, the use of {} to expand a value is only for inside tag attributes, such as the href="" of an achor tag. It isn't simply that you are inside quote marks; it must be a tag's attribute. Therefore, you need to use an xsl:value-of statement. But, since you're already inside double quotes you either need to use single quotes in the value-of, or break the line up with more xsl:text statements.
Here are some examples (I only tested the first one but the other should be correct even though I typed them in the forum editor):
or
Remember, xslt simply echos what you type in unless it is an xslt command or comment.
cheers,
doug.
Hi guys — I'd just like to raise a flag for the (somewhat overlooked) <xsl:comment> statement, which I always use for this :-)
<script type="text/javascript">
<xsl:comment>
window.location = "<xsl:value-of select="umbraco.library:NiceUrl($test/@id)" />";
//</xsl:comment>
<xsl:text>
</xsl:text>
</script>
/Chriztian
Neat trick Chriztian :)
@Chriztian Nice! You're right... I never even think about the xsl:comment tag. Thanks for reminding us.
cheers,
doug.
Thanks alot for your help! You really helped with your explanations and code!
is working on a reply...