1

I'm trying to use this script

function padNumber(num, len){
    var str = ''+num;
    while(str.length < len){
      str = '0' + str;
      }
      return str;
}

in my xlst file but I get this error when trying to debug.

XslLoadException ---------------- XSLT compile error.

XmlException ------------ Name cannot begin with the ' ' character, hexadecimal value 0x20. Line 522, position 27.

line 522 is

while(str.length < len){

Any suggestions?

5
  • 3
    < is an xml/xslt metacharacter...it cannot appear unencoded within either type of document. it should be &lt; Commented Oct 11, 2012 at 20:27
  • @Rufio post an answer and later, mark it as accepted, so other will know. Commented Oct 11, 2012 at 20:45
  • 2
    @Alfabravo I was hoping Marc B would so he can get the credit Commented Oct 11, 2012 at 21:06
  • @MarcB should do it, indeed! :) Commented Oct 11, 2012 at 21:12
  • no worries, go ahead and accept it yourself. Commented Oct 12, 2012 at 4:05

2 Answers 2

1

For the sake of redability, you can also put the Javascript code within a CDATA section. In this case you don't need to change the JS code.

However, the text in a CDATA section must not contain the string "]]>". If so, this string must be split between two consecutive CDATA sections.

I believe that it is not too-likely for a typical JS code to contain that string, but one must be aware of such possibility, regardless how slim it is.

Sign up to request clarification or add additional context in comments.

Comments

0

< is an xml/xslt metacharacter...it cannot appear unencoded within either type of document. it should be &lt;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.