sccd_to_smcat.xsl 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!-- This XSLT transformation transforms SCCD source files to 'SMCAT', a textual format for state-machine-cat, a renderer of state machines -->
  3. <xsl:stylesheet version="2.0"
  4. xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  5. xmlns:sccd="msdl.uantwerpen.be/sccd">
  6. <xsl:output method="text"/>
  7. <xsl:template match="/">
  8. <xsl:for-each select="sccd:diagram/sccd:class">
  9. <xsl:apply-templates/>
  10. </xsl:for-each>
  11. </xsl:template>
  12. <xsl:template match="sccd:scxml">
  13. <xsl:if test="@initial">
  14. initial_<xsl:value-of select="concat(string(count(ancestor::*)),'_',string(count(preceding-sibling::*)))"/>,
  15. </xsl:if>
  16. <xsl:apply-templates select="(sccd:state|sccd:parallel|sccd:history)[1]"/>
  17. <xsl:if test="@initial">
  18. initial_<xsl:value-of select="concat(string(count(ancestor::*)),'_',string(count(preceding-sibling::*)))"/>
  19. -> <xsl:value-of select="@initial"/>;
  20. </xsl:if>
  21. </xsl:template>
  22. <xsl:template match="sccd:state|sccd:parallel|sccd:history">
  23. <!-- [BEGIN-TEMPLATE-<xsl:value-of select="@id"/>] -->
  24. <xsl:value-of select="@id"/>
  25. <xsl:if test="self::sccd:parallel">
  26. [type=parallel]
  27. </xsl:if>
  28. <xsl:if test="(self::sccd:history)">
  29. <xsl:if test="@type = 'deep'">
  30. [type=deephistory]
  31. </xsl:if>
  32. <xsl:if test="not(@type = 'deep')">
  33. [type=history]
  34. </xsl:if>
  35. </xsl:if>
  36. <xsl:if test="sccd:state|sccd:parallel|sccd:history">
  37. {
  38. <xsl:if test="@initial">
  39. initial_<xsl:value-of select="concat(string(count(ancestor::*)),'_',string(count(preceding-sibling::*)))"/>,
  40. </xsl:if>
  41. <xsl:apply-templates select="(sccd:state|sccd:parallel|sccd:history)[1]"/>
  42. }
  43. </xsl:if>
  44. <xsl:choose>
  45. <xsl:when test="following-sibling::sccd:state | following-sibling::sccd:parallel | following-sibling::sccd:history">
  46. ,
  47. <!-- [NEXT-SIBLING] -->
  48. <xsl:apply-templates select="(following-sibling::sccd:state | following-sibling::sccd:parallel | following-sibling::sccd:history)[1]"/>
  49. </xsl:when>
  50. <xsl:otherwise>
  51. ;
  52. </xsl:otherwise>
  53. </xsl:choose>
  54. <xsl:if test="@initial">
  55. initial_<xsl:value-of select="concat(string(count(ancestor::*)),'_',string(count(preceding-sibling::*)))"/>
  56. -> <xsl:value-of select="@initial"/>;
  57. </xsl:if>
  58. <!-- [BEGIN-TRANSITIONS-<xsl:value-of select="@id"/>] -->
  59. <xsl:for-each select="sccd:transition">
  60. <xsl:value-of select="../@id"/> -> <xsl:value-of select="tokenize(@target,'/')[last()]"/>
  61. <xsl:if test="@event">
  62. : <xsl:value-of select="@event"/>
  63. </xsl:if>
  64. ;
  65. </xsl:for-each>
  66. <!-- [END-TRANSITIONS-<xsl:value-of select="@id"/>] -->
  67. <!-- [END-TEMPLATE-<xsl:value-of select="@id"/>] -->
  68. </xsl:template>
  69. </xsl:stylesheet>