Dejan February 2016

XSLT generate random ID ( letters or numbers or both)

This is my code which is working, it seems it uses version 1.0 but I am not sure if some other version can be used also? Now I need to add just one more element which will have some unique ID sent below the STATUS element, for example CORRELATIONID. How to add it in most simple way? I read something similar for version 2.0 but I am not sure if this is applicable to my code so please tell me what should I do? I am using solely XSLT not with C# or anything similar. Thank you

<?xml version='1.0'?> 
<xsl:stylesheet  
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xmlns:max="http://www.ibm.com/maximo"> 
  <xsl:template match="/"> 
    <max:SyncMXWO Destination="SCCD" Action="urn:processDocument"> 
      <max:MXWOSet>
      <max:WORKORDER>
        <xsl:apply-templates select="UpdateTaskAssignmentEx/Task" />
      </max:WORKORDER>
      </max:MXWOSet> 
    </max:SyncMXWO> 
  </xsl:template> 
  <xsl:template match="Task"> 
    <max:WONUM><xsl:value-of select="CallID"/></max:WONUM> 
    <max:STATUS>COMPLETE</max:STATUS>
  </xsl:template> 
</xsl:stylesheet>

Answers


Martin Honnen February 2016

I think using

  <xsl:template match="Task"> 
    <max:WONUM><xsl:value-of select="CallID"/></max:WONUM> 
    <max:STATUS>COMPLETE</max:STATUS>
    <CORRELATIONID><xsl:value-of select="generate-id()"/></CORRELATIONID>
  </xsl:template> 

should suffice to generate a unique id for each Task element you process in a single run of your XSLT stylesheet.

Post Status

Asked in February 2016
Viewed 2,522 times
Voted 7
Answered 1 times

Search




Leave an answer