-4

In XSL i want to generate ID for TD randomly. Following is my Scenario. For example: i have one row, at the end of the row i press "TAB" key it will generate Second row. On that time i want to put Random ID in all the column in Second row.

If it is possible to generate Id in XSL. I tried the following Code.But It not working for my condition.

If any other way solve this issue. Can anybody have solution?

<variable name="id1" select="generate-id()"/>    
<tr id="{generate-id()}">

Thanks in Advance.

Mathias Müller
  • 22,203
  • 13
  • 58
  • 75
ELAYARAJA
  • 521
  • 3
  • 10
  • 23
  • The generate-id() function returns a unique (not necessarily random) id of a node **in the source document**. I don't think the function can be applied to nodes created by the XSLT stylesheet during the transformation. I didn't understand the part with the TAB key: XSLT takes a source XML document and transforms it into a new one; there is no user interface to the process. – michael.hor257k Feb 14 '14 at 06:20
  • possible duplicate of [Generating random numbers in Javascript in a specific range?](http://stackoverflow.com/questions/1527803/generating-random-numbers-in-javascript-in-a-specific-range) – Thomas Weller Feb 14 '14 at 07:18
  • @ThomasW. it is not a Duplicate Bug... Read my Question Again. I am Asking For XSL With Different Scenario. i already search in Stackoverflow. i didnt get the result then only am asking.... – ELAYARAJA Feb 14 '14 at 07:28
  • @michael.hor257k i Understood what you are trying to tell. TAB Key for itself generating new Row using XSLT (Having Code itself) – ELAYARAJA Feb 14 '14 at 07:30
  • If it's a pure XSLT question, then remove the JavaScript and jQuery tags. If it needs JavaScript and jQuery, then please let us know what the relationship between JavaScript and XSL is. Post the relevant parts of the JavaScript. – Thomas Weller Feb 14 '14 at 07:36
  • "*i Understood what you are trying to tell.*" That's good, but I did not understand what you are trying to say (regarding the TAB key). Which seems to me more important at this point, since without it I don't know how to help you. – michael.hor257k Feb 14 '14 at 09:44
  • @michael.hor257k , sorry. TAB key is not an issue ... you just assume that add another row instead of tab key.. – ELAYARAJA Feb 14 '14 at 11:29
  • Can you pass a *seed* as a parameter to your stylesheet? Alternatively, does your processor support the EXSLT date-time() function? Which processor do you use anyway? – michael.hor257k Feb 14 '14 at 11:44

1 Answers1

1

Usually it is not possible to create random numbers using XSLT, because XSLT is expected to produce the same output on the same input - which would not be the case if it produces random numbers while processing.

However, some XSLT processors have implemented random number functions, e.g. the EXSLT extensions. See the description of Random in particular.

However, also read the warning which they give for using the function:

Using EXSLT will only make your stylesheet portable amongst the implementations that support EXSLT. Note that there is no requirement for XSLT processors that are compliant to XSLT to support the extensions described within EXSLT.

Thomas Weller
  • 55,411
  • 20
  • 125
  • 222