Copied to clipboard

Flag this post as spam?

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


  • Ian Banks 24 posts 44 karma points
    Jan 05, 2011 @ 15:06
    Ian Banks
    0

    Illegal xslt characters

    Hi

    This is really simple but I am having trouble with some xslt javascript encoding, I have the following code

     

    <script>
            function removeSpaces(string) {
                var tstring = "";
                string = '' + string;
                splitstring = string.split(" ");
                for(i = 0; i &gt; splitstring.length; i++)
                tstring += splitstring[i];
                return tstring;
    }
    var csv = removeSpaces("Win a Supersize Allotment Collection");
    document.write("<input type=\"hidden\" name=\"fileLocation\" value=\"/var/websites/gw/csv/comp_" + csv + ".csv\" />");

    I am getting the following errors

    System.Xml.XmlException: '\' is an unexpected token. The expected token is '"' or '''. Line 47, position 29.
    at System.Xml.XmlTextReaderImpl.Throw(Exception e)
    at System.Xml.XmlTextReaderImpl.Throw(String res, String[] args)
    at System.Xml.XmlTextReaderImpl.ThrowUnexpectedToken(String expectedToken1, String expectedToken2)
    at System.Xml.XmlTextReaderImpl.ParseAttributes()
    at System.Xml.XmlTextReaderImpl.ParseElement()
    at System.Xml.XmlTextReaderImpl.ParseElementContent()
    at System.Xml.XmlTextReaderImpl.Read()
    at System.Xml.Xsl.Xslt.XsltInput.ReadNextSiblingHelper()
    at System.Xml.Xsl.Xslt.XsltInput.ReadNextSibling()
    at System.Xml.Xsl.Xslt.XsltInput.MoveToFirstChildAny()
    at System.Xml.Xsl.Xslt.XsltInput.MoveToFirstChild()
    at System.Xml.Xsl.Xslt.XsltLoader.LoadInstructions(List`1 content, InstructionFlags flags)
    at System.Xml.Xsl.Xslt.XsltLoader.LoadLiteralResultElement(Boolean asStylesheet)
    at System.Xml.Xsl.Xslt.XsltLoader.LoadInstructions(List`1 content, InstructionFlags flags)
    at System.Xml.Xsl.Xslt.XsltLoader.LoadLiteralResultElement(Boolean asStylesheet)
    at System.Xml.Xsl.Xslt.XsltLoader.LoadInstructions(List`1 content, InstructionFlags flags)
    at System.Xml.Xsl.Xslt.XsltLoader.LoadTemplate(NsDecl stylesheetNsList)
    at System.Xml.Xsl.Xslt.XsltLoader.LoadRealStylesheet()
    at System.Xml.Xsl.Xslt.XsltLoader.LoadDocument()
    at System.Xml.Xsl.Xslt.XsltLoader.LoadStylesheet(XmlReader reader, Boolean include)

  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    Jan 05, 2011 @ 15:49
    Lee Kelleher
    0

    Hi Ian,

    The error is to do with the HTML <input> tag in your JavaScript.  The XSLT processor sees an opening bracket - then reads the backslash and throws an error (because that's illegal XML syntax!)

    If you aren't using any XSL tags in your JavaScript block, then I'd advise you to wrap it in an <xsl:text> tag:

    <xsl:text disable-output-escaping="yes"><![CDATA[
        <script type="text/javascript">
            function removeSpaces(string) {
                ...
            }
        </script>
    ]]></xsl:text>

    Cheers, Lee.

  • Ian Banks 24 posts 44 karma points
    Jan 05, 2011 @ 16:05
    Ian Banks
    0

    Thanks but I will probably need to use xsl tags in within the script block.

    Thanks

    Ian Banks

  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    Jan 05, 2011 @ 16:10
    Lee Kelleher
    0

    Hi Ian,

    One way is to exit out of the <xsl:text> block, like this:

    <xsl:text disable-output-escaping="yes"><![CDATA[
        <script type="text/javascript">
            function removeSpaces(string) {
                ...
                var foo = ']]></xsl:text>
    <xsl:value-of select="$currentPage/@nodeName" />
    <xsl:text disable-output-escaping="yes"><![CDATA[';
                ...
            }
        </script>
    ]]></xsl:text>

    ... it's not the prettiest code - but it will render out correctly.

    Cheers, Lee.

  • Ian Banks 24 posts 44 karma points
    Jan 05, 2011 @ 17:29
    Ian Banks
    0

    Ok thanks will give that a try

     

    Thanks

    Ian Banks

Please Sign in or register to post replies

Write your reply to:

Draft