开发者

Testing javascript output in XSL

I am attempting to bring the current url into my xsl. The only way I found to do this was using javascript. The problem is the output I'm getting from javascript isn't what I was expecting.

document.location: http://mydomainname/PressRoom/Pages/PressReleases.aspx?start=1

        <xsl:variable name="start">
          开发者_如何学C      <![CDATA[
                <script type="text/javascript">
                    urlString = new String(document.location);
                    nwls = urlString.split('start=');
                    document.write(nwls[1]);                    
                </script>
                ]]>
        </xsl:variable> 
        start=<xsl:value-of select="$start" disable-output-escaping="yes" />

        <xsl:if test="$start = '1'">
          start variable contains 1
        </xsl:if>

output: start= 1

The test for $start = 1 is not true

If I check that $start contains 'script type=' that test is true

How can I test the variable $start with disable output escaping?

Thanks.


Instead of

            <![CDATA[
            <script type="text/javascript">
                urlString = new String(document.location);
                nwls = urlString.split('start=');
                document.write(nwls[1]);                    
            </script>
            ]]>

you want

            <script type="text/javascript">
            <![CDATA[
                urlString = new String(document.location);
                nwls = urlString.split('start=');
                document.write(nwls[1]);                    
            ]]>
            </script>

The former is a text block containing the text "<script...>" and the latter is a <script> element containing the text inside the CDATA section.

But I think you're confused about what happens when. The XSL engine runs and completes before scripts are run. So you can't test whether start is 1 inside, because the JavaScript environment hasn't been set up yet.

Also be aware that some older versions of Firefox closed the document before applying XSL, which means that document.write, which starts a new document if the existing one has been closed, will blow away the XSL generated content on those browsers.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜