Question

Okay, so I have never used XSLT before, and I saw a couple of examples online. However, I wasn't exactly sure what each of the examples was looking at in terms of node location, template matching, etc.

But essentially, I have this XML file, a sample process definition from an Activiti workflow:

<?xml version="1.0" encoding="UTF-8" ?>

<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:activiti="http://activiti.org/bpmn"
   xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC"
   xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema"
   expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://alfresco.org">

    <process id="activitiAdhoc" name="Adhoc Activiti Process">

        <startEvent id="start"
            activiti:formKey="wf:submitAdhocTask" />
        <sequenceFlow id='flow1' 
            sourceRef='start'
            targetRef='adhocTask' />

        <userTask id="adhocTask" name="Adhoc Task"
            activiti:formKey="wf:adhocTask">
           <extensionElements>
               <activiti:taskListener event="create" class="org.alfresco.repo.workflow.activiti.tasklistener.ScriptTaskListener">
                  <activiti:field name="script">
                     <activiti:string>
                      if (typeof bpm_workflowDueDate != 'undefined') task.dueDate = bpm_workflowDueDate
                      if (typeof bpm_workflowPriority != 'undefined') task.priority = bpm_workflowPriority;
                     </activiti:string>
                  </activiti:field>
               </activiti:taskListener>
           </extensionElements>
            <humanPerformer>
                <resourceAssignmentExpression>
                    <formalExpression>${bpm_assignee.properties.userName}</formalExpression>
                </resourceAssignmentExpression>
            </humanPerformer>
        </userTask>

        <sequenceFlow id='flow2' 
        sourceRef='adhocTask'
            targetRef='verifyTaskDone' />

        <userTask id="verifyTaskDone" name="Verify Adhoc Task Completed."
            activiti:formKey="wf:completedAdhocTask" >
            <documentation>
                Verify the arbitrary task was completed.
            </documentation>
            <extensionElements>
               <activiti:taskListener event="create" class="org.alfresco.repo.workflow.activiti.tasklistener.ScriptTaskListener">
                  <activiti:field name="script">
                     <activiti:string>
                        if (typeof bpm_workflowDueDate != 'undefined') task.dueDate = bpm_workflowDueDate
                        if (typeof bpm_workflowPriority != 'undefined') task.priority = bpm_workflowPriority;

                        if (wf_notifyMe)
                        {
                           var mail = actions.create("mail");
                           mail.parameters.to = initiator.properties.email;
                           mail.parameters.subject = "Adhoc Task " + bpm_workflowDescription;
                           mail.parameters.from = bpm_assignee.properties.email;
                           mail.parameters.text = "It's done";
                           mail.execute(bpm_package);
                        }
                     </activiti:string>
                  </activiti:field>
               </activiti:taskListener>
           </extensionElements>
            <humanPerformer>
                <resourceAssignmentExpression>
                    <formalExpression>${initiator.exists() ? initiator.properties.userName : 'admin'}</formalExpression>
                </resourceAssignmentExpression>
            </humanPerformer>
        </userTask>

        <sequenceFlow id='flow3' sourceRef='verifyTaskDone'
            targetRef='theEnd' />

        <endEvent id="theEnd" />

   </process>

   <!-- Graphical representaion of diagram -->
   <bpmndi:BPMNDiagram id="BPMNDiagram_activitiAdhoc">
      <bpmndi:BPMNPlane bpmnElement="activitiAdhoc" id="BPMNPlane_activitiAdhoc">
         <bpmndi:BPMNShape bpmnElement="start"
            id="BPMNShape_start">
            <omgdc:Bounds height="35" width="35" x="30" y="200"></omgdc:Bounds>
         </bpmndi:BPMNShape>
         <bpmndi:BPMNShape bpmnElement="adhocTask"
            id="BPMNShape_adhocTask">
            <omgdc:Bounds height="55" width="105" x="130"
               y="190"></omgdc:Bounds>
         </bpmndi:BPMNShape>
         <bpmndi:BPMNShape bpmnElement="verifyTaskDone"
            id="BPMNShape_verifyTaskDone">
            <omgdc:Bounds height="55" width="105" x="290"
               y="190"></omgdc:Bounds>
         </bpmndi:BPMNShape>
         <bpmndi:BPMNShape bpmnElement="theEnd"
            id="BPMNShape_theEnd">
            <omgdc:Bounds height="35" width="35" x="455" y="200"></omgdc:Bounds>
         </bpmndi:BPMNShape>
         <bpmndi:BPMNEdge bpmnElement="flow1" id="BPMNEdge_flow1">
            <omgdi:waypoint x="65" y="217"></omgdi:waypoint>
            <omgdi:waypoint x="130" y="217"></omgdi:waypoint>
         </bpmndi:BPMNEdge>
         <bpmndi:BPMNEdge bpmnElement="flow2" id="BPMNEdge_flow2">
            <omgdi:waypoint x="235" y="217"></omgdi:waypoint>
            <omgdi:waypoint x="290" y="217"></omgdi:waypoint>
         </bpmndi:BPMNEdge>
         <bpmndi:BPMNEdge bpmnElement="flow3" id="BPMNEdge_flow3">
            <omgdi:waypoint x="395" y="217"></omgdi:waypoint>
            <omgdi:waypoint x="455" y="217"></omgdi:waypoint>
         </bpmndi:BPMNEdge>
      </bpmndi:BPMNPlane>
   </bpmndi:BPMNDiagram>

</definitions>

And I saw an example from, here:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:template match="@*|node()">
        <xsl:copy>
                <xsl:apply-templates select="@*|node()"/>
        </xsl:copy>
    </xsl:template>
    <xsl:template match="/html/body/content/h2">
        <xsl:copy>
                <xsl:apply-templates/>
        </xsl:copy>
        <p><a href="...">your new link</a></p>
    </xsl:template>
</xsl:stylesheet>

And for my current purposes, I don't really care where I place the link on the form, I just need it to show up first. So I'm just wondering what exactly I should change from that sample to match the elements in my XML file?

Was it helpful?

Solution

I'm not sure if I got you right ... here are some samples how you can match elements of your document. But there are some options more XSLT can be really complex :-D You must allways keep in mind how you travers your tree of nodes.

<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:model="http://www.omg.org/spec/BPMN/20100524/MODEL"
    xmlns:activiti="http://activiti.org/bpmn">

 <!-- example match of definitions -->
 <xsl:template match="model:definitions">
   <!-- here you can do something -->
   <!-- and if you want traverse the rest of the tree -->
   <xsl:apply-templates select="*|@*"/>
 </xsl:template> 

 <!-- example match of userTask -->
 <xsl:template match="model:userTask">
   <!-- here you can do something -->
   <!-- and if you want traverse the rest of the tree -->
   <xsl:apply-templates select="*|@*"/>
 </xsl:template> 

 <!-- example match of an attribute -->
 <xsl:template match="@activiti:formKey">
   <!-- here you can do something -->
 </xsl:template> 

  <!-- this handles all not explicit mentioned nodes ... -->
  <xsl:template match="*|@*">
    <!-- ... and traverse the xml tree -->
    <xsl:apply-templates select="*|@*"/>
  </xsl:template>
</xsl:stylesheet>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top