tags:

views:

79

answers:

2

My source document is:

<?xml version="1.0" encoding="UTF8"?>
 <definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:fn="http://www.w3.org/2005/xpathfunctions" xmlns:svg="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchemainstance" xsi:schemaLocation="http://schema.omg.org/spec/BPMN/2.0 schema\BPMN20.xsd" targetNamespace="http://schema.omg.org/spec/BPMN/2.0"&gt;
 <process id="DA444C7EB7A92BC0EC615091EFE52E9F" name="Process111">
  <laneSet>
    <lane id="BE805267E22661E25210E901418B7DA2" name="Lane111" > 
     <flowNodeRefs>E705CE86B8897B266BA6AC81E2F1A5BC</flowNodeRefs>     
     <flowNodeRefs>643E3A26322BEECB2DBD84BF2A6F9CA5</flowNodeRefs>
    </lane>
    <lane id="2F92C8B27CE52AFDB382D4EAC634E634" name="Lane222" > 
     <flowNodeRefs>A65A0630689FA02F3BBB6AC27D906603</flowNodeRefs>     
     <flowNodeRefs>DDA49A7836C13B7DC3208778C4B03526</flowNodeRefs>
  </lane>
   </laneSet>
  <startEvent id="E705CE86B8897B266BA6AC81E2F1A5BC" name="Start111" /> 
  <endEvent id="643E3A26322BEECB2DBD84BF2A6F9CA5" name="End111" /> 
  <startEvent id="A65A0630689FA02F3BBB6AC27D906603" name="Start222" /> 
  <terminateEvent id="DDA49A7836C13B7DC3208778C4B03526" name="Terminate111" /> 
  </process>
 <process id="A7F84E7EA73F9436DCB925D5C3208227" name="Process2222">
 <laneSet>
  <lane id="B8EE1D7AA494C6D25656434F1CAF803F" name="Lane444" /> 
  </laneSet>
  </process>
  </definitions>

I want to tranform to the target document:

<?xml version="1.0" encoding="UTF-8"?>  
<svg  version="1.1"  xmlns="http://www.w3.org/2000/svg"  xmlns.x="org.w3c.dom.svg"  xmlns:xlink="http://www.w3.org/1999/xlink"  >
 <g id="BPMNDIAGRAM" transform="scale(1)"> 
 <g id="POOLS" class="POOLS">
 <g id="DA444C7E-B7A9-2BC0-EC61-5091EFE52E9F" class="POOL" >
  <g >
   <text >
   <tspan >Process111</tspan>
   </text>
  </g>
  <g id="BE805267-E226-61E2-5210-E901418B7DA2" class="LANE"  PoolID="DA444C7E-B7A9-2BC0-EC61-5091EFE52E9F">
   <g>
    <text >
    <tspan>Lane111</tspan>
    </text>
   </g>
   <g id="EVENTS_BE805267-E226-61E2-5210-E901418B7DA2" class="EVENTS">
    <g id="643E3A26-322B-EECB-2DBD-84BF2A6F9CA5" class="ENDEVENT"  LaneID="BE805267-E226-61E2-5210-E901418B7DA2">
     <text >
     <tspan >End111</tspan>
     </text>
    </g>
    <g id="E705CE86-B889-7B26-6BA6-AC81E2F1A5BC" class="STARTEVENT"  LaneID="BE805267-E226-61E2-5210-E901418B7DA2">
      <text >
      <tspan x="0" dy="10">Start111</tspan>
      </text>
    </g>
   </g>
  </g>
  <g id="2F92C8B2-7CE5-2AFD-B382-D4EAC634E634" class="LANE"  PoolID="DA444C7E-B7A9-2BC0-EC61-5091EFE52E9F">
   <g >
    <text >
    <tspan x="0" dy="10">Lane222</tspan>
    </text>
   </g>
   <g id="EVENTS_2F92C8B2-7CE5-2AFD-B382-D4EAC634E634" class="EVENTS">
    <g id="A65A0630689FA02F3BBB6AC27D906603" class="STARTEVENT"  LaneID="2F92C8B2-7CE5-2AFD-B382-D4EAC634E634">
      <text >
      <tspan x="0" dy="10">Start222</tspan>
      </text>
    </g>
    <g id="DDA49A78-36C1-3B7D-C320-8778C4B03526" class="TERMINATEEVENT"  LaneID="2F92C8B2-7CE5-2AFD-B382-D4EAC634E634">
     <text >
     <tspan x="0" dy="10">Terminate111</tspan>
     </text>
    </g>    
   </g>   
  </g>
 </g>
 <g id="A7F84E7E-A73F-9436-DCB9-25D5C3208227" class="POOL" > 
  <g >
   <text >
    <tspan >Process2222</tspan>
   </text>
  </g>

 <g id="B8EE1D7A-A494-C6D2-5656-434F1CAF803F" class="LANE"  PoolID="A7F84E7E-A73F-9436-DCB9-25D5C3208227">
  <g >
   <text >
    <tspan>Lane444</tspan>
   </text>
  </g>     
 </g>
 </g>
 </g>
</g>
</svg>

And my transformation file is as following code:

<?xml version="1.0" encoding="Windows-1252"?>
<xsl:stylesheet version="2.0" 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
    xmlns:svg="http://www.w3.org/2000/svg" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:xlink="http://www.w3.org/1999/xlink"&gt;
    <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
    <!-- BPMN 2.0 Transformation: BPMN2.0 xml-to-SVG xml -->    
  <xsl:strip-space elements="*"/>
    <xsl:template match="/">
        <svg>
            <xsl:attribute name="xmlns.x">org.w3c.dom.svg</xsl:attribute>   
            <xsl:attribute name="targetNamespace">http://schema.omg.org/spec/BPMN/2.0&lt;/xsl:attribute&gt;
            <xsl:call-template name="rootElementTemplate"/>                     
        </svg>      
    </xsl:template>
    <!-- rootElementTemplate -->
    <xsl:template name="rootElementTemplate">
        <g>             
         <!--call the other templates-->
            <xsl:call-template name="pools"/>
        </g>
    </xsl:template>
    <xsl:template name="pools">
        <g>
            <xsl:attribute name="id">POOLS</xsl:attribute>
            <xsl:attribute name="class">POOLS</xsl:attribute>
            <xsl:apply-templates select="process"/>
        </g>
    </xsl:template>

<xsl:template match="process">
    <g>
      <xsl:attribute name="id"><xsl:value-of select="."/></xsl:attribute> 
      <xsl:attribute name="class">POOL</xsl:attribute>
        <xsl:call-template name="text1"/>
    </g>
</xsl:template>

<xsl:template name="text1" >
<xsl:for-each select="@name">
 <g >
    <xsl:element name="text">
        <xsl:element name="tspan"><xsl:value-of select= "."/></xsl:element>
    </xsl:element>  
 </g>
 </xsl:for-each>
</xsl:template>

<xsl:template match="lane">
  <g id="{@id}" class="LANE" >
      <xsl:apply-templates select="@name"/>
     <xsl:variable name="p" select="count(preceding-sibling::lane)+1"/>
     <xsl:variable name="ref" select="ancestor::process/*[$p+1]"/>
     <xsl:apply-templates select="$ref"/>
  </g>
</xsl:template>

<xsl:template match="startevent">
  <g id="{@id}" class="STARTEVENT" name="{@name}" />
</xsl:template>

</xsl:stylesheet>

I don't know why it doesn't work? Please help me

A: 

This stylesheet:

<xsl:stylesheet version="1.0"
exclude-result-prefixes="m"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:m="http://www.omg.org/spec/BPMN/20100524/MODEL"
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:x="org.w3c.dom.svg">
    <xsl:variable name="attrSet">
        <dummy x="0" dy="10"/>
    </xsl:variable>
    <xsl:template match="m:definitions">
        <svg version="1.1">
            <g id="BPMNDIAGRAM" transform="scale(1)">
                <g id="POOLS" class="POOLS">
                    <xsl:apply-templates />
                </g>
            </g>
        </svg>
    </xsl:template>
    <xsl:template match="m:process">
        <g class="POOL">
            <xsl:apply-templates select="@id"/>
            <xsl:apply-templates select="@name|m:laneSet/*"/>
        </g>
    </xsl:template>
    <xsl:template match="*">
        <xsl:param name="idName" select="'PoolID'"/>
        <xsl:param name="id" select="../../@id"/>
        <g class="{translate(name(),
                             'lanedvtsrmi',
                             'LANEDVTSRMI')}">
            <xsl:attribute name="{$idName}">
                <xsl:apply-templates select="$id" mode="id"/>
            </xsl:attribute>
            <xsl:apply-templates select="@id"/>
            <xsl:apply-templates select="@name"/>
            <xsl:apply-templates/>
        </g>
    </xsl:template>
    <xsl:template match="m:flowNodeRefs[position()!=1]"/>
    <xsl:template match="m:flowNodeRefs[1]">
        <g class="EVENTS">
            <xsl:attribute name="id">
                <xsl:text>EVENTS_</xsl:text>
                <xsl:apply-templates select="../@id" mode="id"/>
            </xsl:attribute>
            <xsl:apply-templates select="../../../*[@id = current()/../*]">
                <xsl:with-param name="idName" select="'LaneID'"/>
                <xsl:with-param name="id" select="../@id"/>
            </xsl:apply-templates>
        </g>
    </xsl:template>
    <xsl:template match="@id">
        <xsl:attribute name="id">
            <xsl:apply-templates select="." mode="id"/>
        </xsl:attribute>
    </xsl:template>
    <xsl:template match="@id" mode="id">
        <xsl:value-of select="concat(substring(.,1,8),'-',
                                     substring(.,9,4),'-',
                                     substring(.,13,4),'-',
                                     substring(.,17,4),'-',
                                     substring(.,21))"/>
    </xsl:template>
    <xsl:template match="@name">
        <g>
            <text>
                <tspan>
                    <xsl:copy-of select="document('')/*/xsl:variable
                                    [@name='attrSet']/*/@*
                                    [not(current()/../self::m:endEvent|
                                         current()/../self::m:process)]
                                    [not(generate-id(current()/..) =
                                         generate-id(current()/../../m:lane[1]))]"/>
                    <xsl:value-of select="."/>
                </tspan>
            </text>
        </g>
    </xsl:template>
</xsl:stylesheet>

Output:

<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:x="org.w3c.dom.svg">
    <g id="BPMNDIAGRAM" transform="scale(1)">
        <g id="POOLS" class="POOLS">
            <g class="POOL" id="DA444C7E-B7A9-2BC0-EC61-5091EFE52E9F">
                <g>
                    <text>
                        <tspan>Process111</tspan>
                    </text>
                </g>
                <g class="LANE" PoolID="DA444C7E-B7A9-2BC0-EC61-5091EFE52E9F" id="BE805267-E226-61E2-5210-E901418B7DA2">
                    <g>
                        <text>
                            <tspan>Lane111</tspan>
                        </text>
                    </g>
                    <g class="EVENTS" id="EVENTS_BE805267-E226-61E2-5210-E901418B7DA2">
                        <g class="STARTEVENT" LaneID="BE805267-E226-61E2-5210-E901418B7DA2" id="E705CE86-B889-7B26-6BA6-AC81E2F1A5BC">
                            <g>
                                <text>
                                    <tspan x="0" dy="10">Start111</tspan>
                                </text>
                            </g>
                        </g>
                        <g class="ENDEVENT" LaneID="BE805267-E226-61E2-5210-E901418B7DA2" id="643E3A26-322B-EECB-2DBD-84BF2A6F9CA5">
                            <g>
                                <text>
                                    <tspan>End111</tspan>
                                </text>
                            </g>
                        </g>
                    </g>
                </g>
                <g class="LANE" PoolID="DA444C7E-B7A9-2BC0-EC61-5091EFE52E9F" id="2F92C8B2-7CE5-2AFD-B382-D4EAC634E634">
                    <g>
                        <text>
                            <tspan x="0" dy="10">Lane222</tspan>
                        </text>
                    </g>
                    <g class="EVENTS" id="EVENTS_2F92C8B2-7CE5-2AFD-B382-D4EAC634E634">
                        <g class="STARTEVENT" LaneID="2F92C8B2-7CE5-2AFD-B382-D4EAC634E634" id="A65A0630-689F-A02F-3BBB-6AC27D906603">
                            <g>
                                <text>
                                    <tspan x="0" dy="10">Start222</tspan>
                                </text>
                            </g>
                        </g>
                        <g class="TERMINATEEVENT" LaneID="2F92C8B2-7CE5-2AFD-B382-D4EAC634E634" id="DDA49A78-36C1-3B7D-C320-8778C4B03526">
                            <g>
                                <text>
                                    <tspan x="0" dy="10">Terminate111</tspan>
                                </text>
                            </g>
                        </g>
                    </g>
                </g>
            </g>
            <g class="POOL" id="A7F84E7E-A73F-9436-DCB9-25D5C3208227">
                <g>
                    <text>
                        <tspan>Process2222</tspan>
                    </text>
                </g>
                <g class="LANE" PoolID="A7F84E7E-A73F-9436-DCB9-25D5C3208227" id="B8EE1D7A-A494-C6D2-5656-434F1CAF803F">
                    <g>
                        <text>
                            <tspan>Lane444</tspan>
                        </text>
                    </g>
                </g>
            </g>
        </g>
    </g>
</svg>

Note: These lines

<xsl:apply-templates select="@id"/>
<xsl:apply-templates select="@name|m:laneSet/*"/>

And

<xsl:apply-templates select="@id"/>
<xsl:apply-templates select="@name"/>
<xsl:apply-templates/>

Could be like

<xsl:apply-templates select="@*|m:laneSet/*"/>

And

<xsl:apply-templates select="@*|*"/>

But, there is no guarantee from the spec that attributes are proccess in any order (beside that before child elements).

Also, I use a tricky way for add x and dy attributes. But the conditions in predicates could be use as test for a xsl:if, adding these attributes with xsl:attribute.

Alejandro
Thank Alejandro, I wanna apply this transformation to extra elements.But I still don't understand some points:1. Why have you used concat(substring(.,1,8),'-', substring(.,9,4),'-', substring(.,13,4),'-', substring(.,17,4),'-', substring(.,21))"/>2. And even in <xsl:template match="@name">. It is really new with me.
@AlejandroI have extra elements which are classified with corresponding groups(parents). For example: inclusivegateway, exclusivegateway, complexgateway that are in GATEWAYS group. And ACTIVITIES group which is parent of TASK, USERTASK, SCRIPTASK, etc.You've already done with EVENTS group that for all elements. So I need to put criteria(xsl:if)...Something like <xsl:if test='')But how to check the substrings which have '#EVENT#' substring will be put inside EVENTS group. And similarly, '#GATEWAY#' will be put inside GATEWAYS group...Thanks,
@user402802: I'm glad this had helped you. So, you could mark this as answer. About your questions: the "concat(substring..." expresion is there because your input has a diferent @id format, check it. The xsl:template[@match="@name"] has a minor... trick? I copy some attributes (inline in the stylesheet, that's way `document('')`) if some predicates are true. As I wrote in NOTE, you could wrap this predicates in a xsl:if/@test with xsl:attributes inside, but that would be verbose.
Alejandro
@user402802: For the GATEWAYS group, look how I output EVENTS group, there you need to output this new group modifying the `xsl:apply-templates select="../../../*[@id = current()/../*]"` according. With a sample I can show you exactly how, but I think you also could do it.
Alejandro
@Alejandro...I think I get your ideas...But in order to make the conditional expression for example with EVENTS group...xsl:apply-templates select="../../../*[@id = current()/../*]" I need to extract which elements(*) have the name like #event#forexample: startevent, endevent...HOw to check it? Could you modify this expression which just containts all elements of event not the other.
@AlejandroCould I use parameter in following template[code]<xsl:template match="bpmn:flowNodeRefs[1]"> <xsl:param name="elementgroup" /> <g class="{translate($elementgroup, 'abcdefghijklmnopqrstuvwxyz', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ')}"> <xsl:attribute name="id"> <xsl:text><xsl:value-of select="{$elementgroup}"/></xsl:text>... <xsl:for-each select="../../../contains(node(),$elementgroup)[id = current()/../*]"> <xsl:apply-templates select="../../../*[@id = current()/../*]">...[/code]
A: 

@Alejandro: I still get confusing the way how to classify in the group ----there are some group with different solution...how to know the prediction result to classify which element in which group? Specially, how to know which sequence flow is inside which process. I just know the reference links are made between the objects that are inside the specific pool(process)

Do you have any ideas?

which function to check whether text result is inside a specific string or not?

You should post follow-up questions as a separate thread, notas an answer. After all, it doesn't really answer *this*question. If it's still the same question, that you want to clarify, edit the question to include the additional information instead.
sth
@user402802: "With a sample I can show you exactly how" was my comment 2 days ago, as it is today.
Alejandro
Where is Alejandro?