0

The below code returns UUID in V4 format i.e 8-4-4-4-12 for a total of 36 characters. I am using https://stackoverflow.com/a/60074845/3747770 to generate the UUID.

<func:function name="Utility:getFormatedV4Uuid">
    <func:result>
        <xsl:text>uuid.</xsl:text>
        <xsl:value-of select="Utility:UUID4()"/>
    </func:result>
</func:function>

But the issue is the function Utility:UUID4 some time returns 35 characters instead of 36 characters and I am unable to reproduce the issue. So I am planning to recursively call the Utility:UUID4 function until it returns 36 characters. How do I recursively call a function Utility:UUID4 until it returns 36 characters in XSLT 1.0? Or, is there anyway to fix the issue?

NJMR
  • 1,886
  • 1
  • 27
  • 46
  • You can call a *named template* recursively. Not sure that's the best solution, though. Might be better to fix the problem at its source - but you're not revealing what it is. BTW, `func:function` is not XSLT 1.0; it's an EXSLT extension. – michael.hor257k Aug 28 '20 at 12:41
  • Updated the question with the link which I am using to generate the UUID. – NJMR Aug 28 '20 at 13:05
  • 1
    Oh, that one. I told you at a comment there that I cannot understand how this problem is possible - let alone reproduce it. – michael.hor257k Aug 28 '20 at 13:09
  • I used oxygen tool for testing the UUID code. I generated around 500 UUIDs and did check the length, it was okay. I am using this UUID code along with many other xslt files, occasionally I get this length error. We use these XSLT files for generating IWXXM METAR/SPECI gmlid's. – NJMR Aug 30 '20 at 14:12

1 Answers1

1

As I said in the comments, I don't know how to reproduce the problem.

To answer your question: you could call the calling function recursively until the called function returns a satisfactory result:

<func:function name="Utility:getFormatedV4Uuid">
    <xsl:variable name="uid" select="Utility:UUID4()"/>
    <func:result>
        <xsl:choose>
            <xsl:when test="string-length($uid) = 36">
                <xsl:text>uuid.</xsl:text>
                <xsl:value-of select="$uid"/>
            </xsl:when>
            <xsl:otherwise>
                <xsl:value-of select="Utility:getFormatedV4Uuid()"/>
            </xsl:otherwise>
        </xsl:choose>
    </func:result>
</func:function>

Untested, because I don't know how to test it without being able to reproduce the problem.

michael.hor257k
  • 113,275
  • 6
  • 33
  • 51