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 > 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)
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:
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 > 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)
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:
Cheers, Lee.
Thanks but I will probably need to use xsl tags in within the script block.
Thanks
Ian Banks
Hi Ian,
One way is to exit out of the <xsl:text> block, like this:
... it's not the prettiest code - but it will render out correctly.
Cheers, Lee.
Ok thanks will give that a try
Thanks
Ian Banks
is working on a reply...