Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • ulrike 3 posts 23 karma points
    Dec 16, 2009 @ 22:34
    ulrike
    0

    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?

  • Douglas Robar 3570 posts 4711 karma points MVP ∞ admin c-trib
    Dec 16, 2009 @ 23:05
    Douglas Robar
    1

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

    <script type="text/javascript">
        <xsl:text disable-output-escaping="yes">&lt;!--</xsl:text>
            window.location = "<xsl:value-of select='umbraco.library:NiceUrl($test/@id)' />"
        <xsl:text>//--></xsl:text>
    </script>

    or

    <script type="text/javascript">
        <xsl:text disable-output-escaping="yes">&lt;!--</xsl:text>
        <xsl:text>window.location = "</xsl:text>
    <xsl:value-of select="umbraco.library:NiceUrl($test/@id)" />
    <xsl:text>"</xsl:text>
        <xsl:text>//--></xsl:text>
    </script

    Remember, xslt simply echos what you type in unless it is an xslt command or comment.

     

    cheers,
    doug.

  • Chriztian Steinmeier 2798 posts 8788 karma points MVP 8x admin c-trib
    Dec 16, 2009 @ 23:31
    Chriztian Steinmeier
    0

    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>&#x0a;</xsl:text>
    </script>

    /Chriztian

  • Laurence Gillian 600 posts 1219 karma points
    Dec 16, 2009 @ 23:42
    Laurence Gillian
    0

    Neat trick Chriztian :)

  • Douglas Robar 3570 posts 4711 karma points MVP ∞ admin c-trib
    Dec 16, 2009 @ 23:43
    Douglas Robar
    0

    @Chriztian Nice! You're right... I never even think about the xsl:comment tag. Thanks for reminding us.

    cheers,
    doug.

  • ulrike 3 posts 23 karma points
    Dec 17, 2009 @ 21:33
    ulrike
    0

    Thanks alot for your help! You really helped with your explanations and code!

Please Sign in or register to post replies

Write your reply to:

Draft