<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="process-definition">
<xsl:element name="decomposition">
<xsl:attribute name="id">
<xsl:value-of select="@name"/>
</xsl:attribute>
<xsl:for-each select="task-node">
<xsl:element name="task">
<xsl:attribute name="id">
<xsl:value-of select="@name"/>
</xsl:attribute>
<name><xsl:value-of select="@name"/></name>
<xsl:choose>
<xsl:when test="not(transition/@to=//process-definition/task-node/@name)">
<flowsInto>
<xsl:element name="nextElementRef">
<xsl:attribute name="id">
<xsl:for-each select="/process-definition/decision" >
<xsl:value-of select="descendant::transition/@to"/>
</xsl:for-each>
</xsl:attribute>
</xsl:element>
</flowsInto>
<flowsInto>
<xsl:element name="nextElementRef">
<xsl:attribute name="id">
<xsl:value-of select="//process-definition/decision/transition/@to"/>
</xsl:attribute>
</xsl:element>
</flowsInto>
</xsl:when>
<xsl:otherwise>
<flowsInto>
<xsl:element name="nextElementRef">
<xsl:attribute name="id">
<xsl:value-of select="transition/@to"/>
</xsl:attribute>
</xsl:element>
</flowsInto>
</xsl:otherwise>
</xsl:choose>
</xsl:element>
</xsl:for-each>
</xsl:element>
</xsl:template>
</xsl:stylesheet>

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xsl:output indent="yes" method="xml"/>
    <xsl:template match="/">
        <xsl:apply-templates select="process-definition"/>
    </xsl:template>
    <xsl:template match="process-definition">
        <decomposition>
            <xsl:attribute name="id">
                <xsl:value-of select="@name"/>
            </xsl:attribute>
            <xsl:apply-templates select="task-node"/>
        </decomposition>
    </xsl:template>
    <xsl:template match="task-node">
        <task>
            <xsl:attribute name="id">
                <xsl:value-of select="@name"/>
            </xsl:attribute>
            <xsl:choose>
                <xsl:when test="contains(./transition/@to,'Condition')">
                    <xsl:variable name="to" select="./transition/@to"/>
                    <xsl:apply-templates select="../decision[./@name=$to]"/>
                </xsl:when>
                <xsl:otherwise>
                    <xsl:apply-templates select="transition"/>
                </xsl:otherwise>
            </xsl:choose>
        </task>
    </xsl:template>
    <xsl:template match="transition">
        <flowsInto>
            <nextElementRef>
                <xsl:attribute name="id">
                    <xsl:value-of select="@to"/>
                </xsl:attribute>
            </nextElementRef>
        </flowsInto>
    </xsl:template>
    <xsl:template match="decision">
        <xsl:apply-templates select="transition"/>
    </xsl:template>
</xsl:stylesheet>
Comments
Very nice solution!
This article has been dead for over six months. Start a new discussion instead.