0

Is it possible to get a unique long number in xslt?
I am accessing more than one time in a single translation.
I tried using using currentTimeStamp but it didn't work.

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema"
  exclude-result-prefixes="xs" xmlns:timeStamp="java.lang.System">
    <xsl:template match="/">
            <xsl:for-each select="Client">
            <xsl:variable name="ClientPK1" select="concat('-',timeStamp:currentTimeMillis())"/>
            <xsl:variable name="ClientPK2" select="concat('-',timeStamp:currentTimeMillis())"/>
Himanshu Yadav
  • 13,315
  • 46
  • 162
  • 291
  • Can you explain what you're actually trying to achieve with this approach, so that we can see whether or not we need to answer your question, or suggest a better solution for the problem you're actually trying to solve? – Mike 'Pomax' Kamermans Oct 08 '13 at 18:23
  • I am sending xml request to legacy system. When Legacy system sees a PK with negative value, It inserts it in the table. That's why I have to send unique negative PKs. – Himanshu Yadav Oct 08 '13 at 18:26
  • What about having a variable with an initial value of -1, and decrementing it in each iteration? – ppeterka Oct 08 '13 at 18:29
  • Trying to keep it cleaner and curious if there is anyway to get unique long number. – Himanshu Yadav Oct 08 '13 at 18:32
  • I would have to agree with @ppeterka66's: create an `xsl:variable` and set it to -1, then decrement it with each PK selection so that it's always unique, which staying negative. Using a tracking variable is pretty clean, because it lets you document what the value is actually for; and well documented XSLT is the only truly useful XSLT – Mike 'Pomax' Kamermans Oct 08 '13 at 18:32
  • ok. How would I do it? Sorry I am new to XSLT. – Himanshu Yadav Oct 08 '13 at 18:34
  • 1
    If you're new to XSLT, an in/decrement counter can actually be really confusion since you can't "update" a variable -- you set it once, then perform your selection matching recursively with each recursive call in/decrementing the value as a parameter. There is a good SO post on how to achieve a 'global variable' similar to what you need, http://stackoverflow.com/questions/833118/in-xslt-how-do-i-increment-a-global-variable-from-a-different-scope will be worth reading for you. – Mike 'Pomax' Kamermans Oct 08 '13 at 18:39

1 Answers1

0

Generating numbers is not part of the language (XSLT is functional). But still there are extensions you could use. Check out: exslt.org

burgi
  • 1