I get from my xml some integer and I want to get all numbers between 1 and the gotten number .
I want to insert those numbers as a columns names .
Is it possible to do ?
Thanks .
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I. XSLT 2.0 solution:
II. XSLT 1.0 DVC solution
The answer by @nd (using primitive recursion) is a good one.
However, if a sequence of numbers is to be generated with sufficiently big length (1000 or more) primitive recursion typically ends abnormally with stack overflow due to too-deep recursion.
The DVC (Divide and Conquer) method can be used to avoid call stack overflow for any practical case:
When this transformation is applied on any XML document (not used), it outputs the numbers from one to one million. The maximum dept of the call stack during this transformation is only 19 (log2(N)).
III. Non-recursive XSLT 1.0 solution:
In case the length of the numeric sequence to be generated is not too big (more precisely , doesn’t exceed the number of the available nodes in an XML document (such as the XSLT stylesheet itself)), then we can use a non-recursive solution, known as the Piez method:
when this transformation is applied to any XML document (not used) it produces the numbers from 1 to 40: