Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF "Technology" (Ecore Tools, EMFatic, etc)  » [EMF Compare] XSLT File
[EMF Compare] XSLT File [message #608720] Thu, 12 July 2007 14:02
Eclipse UserFriend
Originally posted by: user.domain.invalid

This is a multi-part message in MIME format.
--------------000801010703030000020201
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

A file for taking an EMF-Diff & rendering the top pane as HTML

Adam

--------------000801010703030000020201
Content-Type: text/xml;
name="EMF-DIFF2HTML.xslt"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="EMF-DIFF2HTML.xslt"

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

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xmi="http://schema.omg.org/spec/XMI/2.1"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:diff="http://www.eclipse.org/emf/compare/diff/1.0"
xmlns:match="http://www.eclipse.org/emf/compare/match/1.0"
xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore"
xmlns:notation="http://www.ibm.com/xtools/1.5.0/Notation"
xmlns:uml="http://www.eclipse.org/uml2/2.1.0/UML"
xmlns:umlnotation="http://www.ibm.com/xtools/1.5.0/Umlnotation">
<xsl:output method="html" version="1.0" encoding="utf-8"
indent="yes" />

<xsl:template match="/">
<xsl:apply-templates />
</xsl:template>



<!-- Find each file


<leftElement href=" file:/D:/Data/Java/workspaces/3.2.2-gash/XMIDiffTest/Advance d%20Trace%20TestBefore1.uml#_2IHQUQ3aEdy0fvloa5NWrg "/>
<rightElement href=" file:/D:/Data/Java/workspaces/3.2.2-gash/XMIDiffTest/Advance d%20Trace%20TestAfter1.uml#_2IHQUQ3aEdy0fvloa5NWrg "/>

specific template for stripping out an href

-->
<xsl:template match="diff:ModelInputSnapshot">

<xsl:variable name="date">
<xsl:value-of select="@date" />
</xsl:variable>


<!-- <subMatchElements xsi:type="match:Match2Elements" similarity="1.0">
<leftElement href=" file:/D:/Data/Java/workspaces/3.3/XMI_test/AdvancedTraceTest B4.uml#_2IHQUQ3aEdy0fvloa5NWrg "/>
<rightElement href=" file:/D:/Data/Java/workspaces/3.3/XMI_test/Advanced%20Trace% 20TestAfter1.uml#_2IHQUQ3aEdy0fvloa5NWrg "/>
</subMatchElements> -->

<xsl:variable name="SME" select="//subMatchElements[1]" />
<xsl:variable name="LHE" select="$SME/leftElement/@href" />
<xsl:variable name="LHR" select="$SME/rightElement/@href" />



<xsl:variable name="LHD">
<xsl:call-template name="getFN">
<xsl:with-param name="f_string" select="$LHE" />
</xsl:call-template>
</xsl:variable>
<xsl:variable name="RHD">
<xsl:call-template name="getFN">
<xsl:with-param name="f_string" select="$LHR" />
</xsl:call-template>

</xsl:variable>


<!-- <xsl:message>
p_file = <xsl:value-of select="$p_file"/>
docFn = <xsl:value-of select="$docFn"/>
xmi_id = <xsl:value-of select="$xmi_id"/>
</xsl:message> -->

<!-- <xsl:message>
date =
<xsl:value-of select="$date" />
</xsl:message> -->

<xsl:call-template name="processDiff">
<xsl:with-param name="p_node" select="diff/ownedElements" />
<xsl:with-param name="date" select="$date" />
<xsl:with-param name="LHD" select="$LHD" />
<xsl:with-param name="RHD" select="$RHD" />
</xsl:call-template>

</xsl:template>



<xsl:template name="processDiff">
<xsl:param name="p_node" />
<xsl:param name="date" />
<xsl:param name="LHD">LHD</xsl:param>
<xsl:param name="RHD">RHD</xsl:param>

<xsl:variable name="Model_Name">
<xsl:call-template name="getname">
<xsl:with-param name="p_file"
select="$p_node/subDiffElements[1]/leftParent/@href" />
</xsl:call-template>
</xsl:variable>





<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta content="text/html; charset=UTF-8"
http-equiv="content-type" />
<title>View of EMF-DIFF</title>
<style type="text/css">
<xsl:comment><![CDATA[
..docTitle{font-size:18.0pt;font-family:Arial;color:darkblue ;font-weight: bold;text-align:center;}
..docSubTitle{font-size:14.0pt;font-family:Arial;color:darkb lue;font-weight: bold;text-align:center;}
..docSubSubTitle{font-size:12.0pt;color:darkblue;font-weight : bold;text-align:left;}
..docBoldBlue{color:darkblue;font-weight: bold;text-align:left;}
..docBlue{color:darkblue;text-align:left;}
..divCenter{text-align:center;}



h1 {
font-size: 24px;
line-height: normal;
font-weight: bold;
background-color: #f0f0f0;
color: #003366;
border-bottom: 1px solid #3c78b5;
padding: 2px;
margin: 36px 0px 4px 0px;
}

td.tableheader{
text-align: left;color:darkblue;
font-weight: normal;
background:#f0f0f0;
padding:0cm 5.4pt 0cm 5.4pt;
font-size:12.0pt;

}
td.W10{width: 10%;text-align:left;font-size:12.0pt;}
td.W20{width: 20%;text-align:left;font-size:12.0pt;}
td.W80{width: 80%;text-align:left;font-size:12.0pt;}

..filler_td{background-color:lightyellow}
body{font-family:Arial;font-size:12.0pt;}

..StdDiv{font-size:12.0pt;}
..Model{color:darkblue;font-weight: bold}

]]>
</xsl:comment>
</style>
</head>
<body>
<div class="divCenter">
<span class="docTitle">XMI Model Comparison</span>
</div>
<h1>
<span class="docSubTitle">Model Information</span>
</h1>
<table style="text-align: left; width: 100%;" border="0"
cellpadding="2" cellspacing="2">
<tbody>

<tr>
<td class="docBoldBlue">Model :</td>
<td class="Model">
<xsl:value-of select="$Model_Name" />
<!--
<xsl:call-template name="getname">
<xsl:with-param name="p_file"
select="$p_node/leftParent/@href" />
</xsl:call-template>-->
</td>
</tr>
<tr>
<td class="docBoldBlue">Compared on :</td>
<td>
<xsl:value-of select="$date" />
</td>
</tr>
<tr>
<td class="docBoldBlue">
<xsl:value-of select="'Left hand Document :'" />
</td>
<td>
<xsl:value-of select="$LHD" />
</td>
</tr>

<tr>
<td class="docBoldBlue">
<xsl:value-of select="'Right hand Document :'" />
</td>
<td>
<xsl:value-of select="$RHD" />
</td>
</tr>
</tbody>
</table>
<h1>
<span class="docSubTitle">Comparison</span>
</h1>
<table style="text-align: left; width: 100%;" border="0"
cellpadding="2" cellspacing="2">
<tbody>
<tr>
<th>
<xsl:value-of select="$Model_Name" />
</th>
<!-- <th>Sub Model Element</th>-->
</tr>

<xsl:for-each
select="$p_node/subDiffElements[@xsi:type != 'diff:DiffGroup']">
<xsl:message>
xsi:type 1 =
<xsl:value-of select="@xsi:type" />
</xsl:message>
<tr>
<xsl:call-template name="subdiff">
<xsl:with-param name="p_node"
select="." />
<xsl:with-param name="counter"
select="'0'" />
</xsl:call-template>
</tr>
</xsl:for-each>

<xsl:for-each
select="$p_node/subDiffElements[@xsi:type = 'diff:DiffGroup']">
<!-- <xsl:message>
xsi:type 2 = <xsl:value-of select="@xsi:type" />
</xsl:message> -->

<xsl:call-template name="subdiff">
<xsl:with-param name="p_node"
select="." />
<xsl:with-param name="counter"
select="'1'" />
</xsl:call-template>

</xsl:for-each>


<!-- <xsl:for-each select="//subDiffElements[@xsi:type='diff:RemoveModelElement'] ">
<tr>
<td ><xsl:value-of select="rightParent/@href"/></td>
<td ><xsl:value-of select="leftElement/@href"/></td>
</tr>
</xsl:for-each> -->
</tbody>
</table>
</body>
</html>

</xsl:template>

<xsl:template name="subdiff">
<xsl:param name="p_node" />
<xsl:param name="counter">0</xsl:param>
<!-- <xsl:message>
type =<xsl:value-of select="$p_node/@xsi:type" />
</xsl:message> -->

<xsl:variable name="diffType">
<xsl:value-of select="$p_node/@xsi:type" />
</xsl:variable>
<xsl:variable name="v_count">
<xsl:value-of select="$counter +1" />
</xsl:variable>

<xsl:choose>
<!-- DiffGroup -->
<xsl:when test="$diffType ='diff:DiffGroup'">
<!-- <xsl:message>
V_count = <xsl:value-of select="$v_count" />
count = <xsl:value-of select="$counter" />
</xsl:message> -->

<tr>
<xsl:if test="$counter > 0">
<xsl:call-template name="print-td">
<xsl:with-param name="count"
select="$counter" />
</xsl:call-template>
</xsl:if>
<td class="DiffGroup">
<xsl:call-template name="changeCounter">
<xsl:with-param name="p_node"
select="$p_node" />
</xsl:call-template>
<xsl:value-of select="' changes in : '" />

<xsl:call-template name="getname">
<xsl:with-param name="p_file"
select="$p_node/leftParent/@href" />
</xsl:call-template>

</td>
</tr>

<xsl:for-each select="$p_node/subDiffElements">

<xsl:call-template name="subdiff">
<xsl:with-param name="p_node" select="." />
<xsl:with-param name="counter"
select="$v_count" />
</xsl:call-template>
</xsl:for-each>
</xsl:when>
<!-- Model Element Changes -->
<xsl:when test="$diffType ='diff:RemoveModelElement'">
<tr>
<xsl:if test="$counter > 0">
<xsl:call-template name="print-td">
<xsl:with-param name="count"
select="$counter" />
</xsl:call-template>
</xsl:if>
<td class="RemoveModelElement">
<xsl:text> Model Element </xsl:text>
<xsl:call-template name="getname">
<xsl:with-param name="p_file"
select="$p_node/leftElement/@href" />
</xsl:call-template>
<xsl:text> has been removed </xsl:text>
</td>
</tr>
</xsl:when>
<xsl:when test="$diffType ='diff:AddModelElement'">
<tr>
<xsl:if test="$counter > 0">
<xsl:call-template name="print-td">
<xsl:with-param name="count"
select="$counter" />
</xsl:call-template>
</xsl:if>
<td class="AddModelElement">
<xsl:text> Model Element </xsl:text>
<xsl:call-template name="getname">
<xsl:with-param name="p_file"
select="$p_node/rightElement/@href" />
</xsl:call-template>
<xsl:text> has been added </xsl:text>
</td>
</tr>
</xsl:when>
<xsl:when test="$diffType ='diff:MoveModelElement'">
<tr>
<xsl:if test="$counter > 0">
<xsl:call-template name="print-td">
<xsl:with-param name="count"
select="$counter" />
</xsl:call-template>
</xsl:if>
<td class="MoveModelElement">
<xsl:text> Model Element </xsl:text>
<xsl:call-template name="getname">
<xsl:with-param name="p_file"
select="$p_node/leftParent/@href" />
</xsl:call-template>
<xsl:text> has been moved </xsl:text>
</td>
</tr>
</xsl:when>
<xsl:when test="$diffType ='diff:UpdateModelElement'">
<tr>
<xsl:if test="$counter > 0">
<xsl:call-template name="print-td">
<xsl:with-param name="count"
select="$counter" />
</xsl:call-template>
</xsl:if>
<td class="UpdateModelElement">
<xsl:text> Model Element has been changed from </xsl:text>
<xsl:call-template name="getname">
<xsl:with-param name="p_file"
select="$p_node/leftElement/@href" />
</xsl:call-template>
<xsl:text> to </xsl:text>
<xsl:call-template name="getname">
<xsl:with-param name="p_file"
select="$p_node/rightElement/@href" />
</xsl:call-template>
</td>
</tr>
</xsl:when>
<!-- Attribute Changes -->
<xsl:when test="$diffType ='diff:AddAttribute'">
<tr>
<xsl:if test="$counter > 0">
<xsl:call-template name="print-td">
<xsl:with-param name="count"
select="$counter" />
</xsl:call-template>
</xsl:if>
<td class="AddAttribute">
<xsl:text> Attribute </xsl:text>
<xsl:call-template name="getname">
<xsl:with-param name="p_file"
select="$p_node/rightElement/@href" />
</xsl:call-template>
<xsl:text> has been added </xsl:text>
</td>
</tr>
</xsl:when>
<xsl:when test="$diffType ='diff:RemoveAttribute'">
<tr>
<xsl:if test="$counter > 0">
<xsl:call-template name="print-td">
<xsl:with-param name="count"
select="$counter" />
</xsl:call-template>
</xsl:if>
<td class="RemoveAttribute">
<xsl:text> Attribute </xsl:text>
<xsl:call-template name="getname">
<xsl:with-param name="p_file"
select="$p_node/leftElement/@href" />
</xsl:call-template>
<xsl:text> has been removed </xsl:text>
</td>
</tr>
</xsl:when>
<xsl:when test="$diffType ='diff:UpdateAttribute'">
<tr>
<xsl:if test="$counter > 0">
<xsl:call-template name="print-td">
<xsl:with-param name="count"
select="$counter" />
</xsl:call-template>
</xsl:if>
<td class="UpdateAttribute">
<xsl:text> Attribute has been changed from </xsl:text>
<xsl:call-template name="getname">
<xsl:with-param name="p_file"
select="$p_node/leftElement/@href" />
</xsl:call-template>
<xsl:text> to </xsl:text>
<xsl:call-template name="getname">
<xsl:with-param name="p_file"
select="$p_node/rightElement/@href" />
</xsl:call-template>
</td>
</tr>
</xsl:when>
<!-- Reference Changes -->
<xsl:when test="$diffType ='diff:AddReferenceValue'">
<tr>
<xsl:if test="$counter > 0">
<xsl:call-template name="print-td">
<xsl:with-param name="count"
select="$counter" />
</xsl:call-template>
</xsl:if>
<td class="AddReferenceValue">
<xsl:text> Reference </xsl:text>
<xsl:call-template name="getname">
<xsl:with-param name="p_file"
select="$p_node/rightAddedTarget/@href" />
</xsl:call-template>
<xsl:text> has been added </xsl:text>
</td>
</tr>
</xsl:when>
<xsl:when test="$diffType ='diff:RemoveReferenceValue'">
<tr>
<xsl:if test="$counter > 0">
<xsl:call-template name="print-td">
<xsl:with-param name="count"
select="$counter" />
</xsl:call-template>
</xsl:if>
<td class="RemoveReferenceValue">
<xsl:text> Reference </xsl:text>
<xsl:call-template name="getname">
<xsl:with-param name="p_file"
select="$p_node/leftRemovedTarget/@href" />
</xsl:call-template>
<xsl:text> has been removed </xsl:text>
</td>
</tr>
</xsl:when>
<xsl:when test="$diffType ='diff:UpdateReference'">
<tr>
<xsl:if test="$counter > 0">
<xsl:call-template name="print-td">
<xsl:with-param name="count"
select="$counter" />
</xsl:call-template>
</xsl:if>
<td class="UpdateReference">
<xsl:text> Reference has been changed from </xsl:text>
<xsl:call-template name="getname">
<xsl:with-param name="p_file"
select="$p_node/leftElement/@href" />
</xsl:call-template>
<xsl:text> to </xsl:text>
<xsl:call-template name="getname">
<xsl:with-param name="p_file"
select="$p_node/rightElement/@href" />
</xsl:call-template>
</td>
</tr>
</xsl:when>
<xsl:when
test="$diffType ='diff:UpdateUniqueReferenceValue'">
<tr>
<xsl:if test="$counter > 0">
<xsl:call-template name="print-td">
<xsl:with-param name="count"
select="$counter" />
</xsl:call-template>
</xsl:if>
<td class="UpdateUniqueReferenceValue">
<xsl:text> Reference has been changed from an </xsl:text>
<xsl:call-template name="getUpdatedRef">
<xsl:with-param name="p_file"
select="$p_node/leftElement/@href" />
</xsl:call-template>
<xsl:text> to an </xsl:text>
<xsl:call-template name="getUpdatedRef">
<xsl:with-param name="p_file"
select="$p_node/rightElement/@href" />
</xsl:call-template>
</td>
</tr>
</xsl:when>



</xsl:choose>




<!-- <xsl:for-each select="//subDiffElements[@xsi:type='diff:RemoveModelElement'] ">
<tr>
<td ><xsl:value-of select="rightParent/@href"/></td>
<td ><xsl:value-of select="leftElement/@href"/></td>
</tr>
</xsl:for-each> -->

</xsl:template>


<xsl:template name="getUpdatedRef">
<xsl:param name="p_file"></xsl:param>
<xsl:variable name="docFn">
<xsl:value-of select="substring-before($p_file,'#')" />
</xsl:variable>
<xsl:variable name="xmi_id">
<xsl:value-of select="substring-after($p_file,'#')" />
</xsl:variable>
<!-- <xsl:message>
p_file = <xsl:value-of select="$p_file"/>
docFn = <xsl:value-of select="$docFn"/>
xmi_id = <xsl:value-of select="$xmi_id"/>
</xsl:message> -->
<xsl:variable name="doc" select="document($docFn)" />
<xsl:variable name="id_El" select="$doc//*[@xmi:id=$xmi_id][1]" />



<xsl:if test="$id_El">
<!-- <xsl:element name="span">
<xsl:attribute name="class">
<xsl:choose>
<xsl:when test="$id_El/@xmi:type">
<xsl:value-of select="$id_El/@xmi:type" />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="name($id_El)" />
</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
</xsl:element> -->

<xsl:choose>
<xsl:when test="$id_El/@type">
<!-- Internal -->
<xsl:variable name="intType" select="$id_El/@type" />
<xsl:variable name="id_El1"
select="$doc//*[@xmi:id=$intType][1]" />
<!-- <xsl:value-of select="concat('Internal Reference : ',$id_El1/@xmi:type,' ', $id_El1/@name)" /> -->
<xsl:element name="span">
<xsl:attribute name="class"
select="'InternalReference'" />
<xsl:value-of select="'Internal Reference :'" />
</xsl:element>

<xsl:element name="span">
<xsl:attribute name="class"
select="$id_El1/@xmi:type" />
<xsl:value-of
select="concat(' ',$id_El1/@xmi:type)" />
</xsl:element>

<xsl:element name="span">
<xsl:attribute name="class" select="'name'" />
<xsl:value-of
select="concat(' ',$id_El1/@name)" />
</xsl:element>

</xsl:when>
<xsl:otherwise>
<xsl:choose>
<xsl:when test="$id_El/type">
<!-- External -->
<xsl:variable name="extType"
select="$id_El/type" />
<!-- <xsl:value-of select="concat('External Reference : ',$extType/@xmi:type,' ', $extType/@href)" /> -->

<xsl:element name="span">
<xsl:attribute name="class"
select="'ExternalReference'" />
<xsl:value-of
select="'External Reference :'" />
</xsl:element>

<xsl:element name="span">
<xsl:attribute name="class"
select="$extType/@xmi:type" />
<xsl:value-of
select="concat(' ',$extType/@xmi:type)" />
</xsl:element>

<xsl:element name="span">
<xsl:attribute name="class"
select="'href'" />
<xsl:value-of
select="concat(' ',$extType/@href)" />
</xsl:element>


</xsl:when>
<xsl:otherwise>
<!-- <xsl:value-of select="$id_El/@name" /> -->
<xsl:value-of select="name($id_El)" />
</xsl:otherwise>
</xsl:choose>
</xsl:otherwise>



</xsl:choose>




</xsl:if>







</xsl:template>




<xsl:template name="getname">
<xsl:param name="p_file"></xsl:param>
<xsl:variable name="docFn">
<xsl:value-of select="substring-before($p_file,'#')" />
</xsl:variable>
<xsl:variable name="xmi_id">
<xsl:value-of select="substring-after($p_file,'#')" />
</xsl:variable>
<!-- <xsl:message>
p_file = <xsl:value-of select="$p_file"/>
docFn = <xsl:value-of select="$docFn"/>
xmi_id = <xsl:value-of select="$xmi_id"/>
</xsl:message> -->
<xsl:variable name="doc" select="document($docFn)" />
<xsl:variable name="id_El" select="$doc//*[@xmi:id=$xmi_id][1]" />



<xsl:if test="$id_El">
<xsl:element name="span">
<xsl:attribute name="class">
<xsl:choose>
<xsl:when test="$id_El/@xmi:type">
<xsl:value-of select="$id_El/@xmi:type" />
</xsl:when>
<xsl:otherwise>
<!-- <xsl:value-of select="$id_El/@name" /> -->
<xsl:value-of select="name($id_El)" />
</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
<xsl:choose>
<xsl:when test="name($id_El) = 'ownedComment'">
<xsl:value-of
select="concat('Comment : ',$id_El/body)" />
</xsl:when>
<xsl:when test="name($id_El) = 'packagedElement'">
<xsl:choose>
<xsl:when test="$id_El/@name">
<xsl:value-of select="$id_El/@name" />
</xsl:when>
<xsl:otherwise>
<!-- <xsl:value-of select="$id_El/@xmi:type" /> -->
<xsl:value-of
select="concat($id_El/@xmi:type,' id = ',$xmi_id)" />
<!-- <xsl:value-of select="concat('PE ',$xmi_id)" /> -->
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
<xsl:choose>
<xsl:when test="$id_El/@name">
<!-- <xsl:message>
name = <xsl:value-of select="$id_El/@name" />
</xsl:message>-->
<xsl:value-of select="$id_El/@name" />
</xsl:when>
<xsl:otherwise>
<!-- <xsl:message>
name of element =<xsl:value-of select="name($id_El)" />
</xsl:message>-->
<xsl:value-of select="name($id_El)" />
</xsl:otherwise>
</xsl:choose>
</xsl:otherwise>
</xsl:choose>


</xsl:element>
</xsl:if>
</xsl:template>



<xsl:template name="print-td">
<xsl:param name="count" />
<xsl:if test="$count"><!-- print the td for this iteration -->
<td class="filler_td"><!-- <xsl:value-of select="$count" /> -->
</td>
<xsl:call-template name="print-td">
<xsl:with-param name="count" select="$count -1" />
</xsl:call-template>
</xsl:if>
</xsl:template>

<xsl:template name="getFN">
<xsl:param name="f_string" />
<xsl:variable name="docFn">
<xsl:value-of select="substring-before($f_string,'#')" />
</xsl:variable>

<xsl:variable name="docFn1">
<xsl:value-of select="substring-after($docFn,'file:/')" />
</xsl:variable>

<xsl:value-of select="$docFn1" />

</xsl:template>


<xsl:template name="changeCounter">
<xsl:param name="p_node" />

<xsl:value-of select=" count($p_node//descendant::subDiffElements[not(@xsi:type='di ff:DiffGroup')]) " />


</xsl:template>



</xsl:stylesheet>

--------------000801010703030000020201--
Previous Topic:[EMF Compare] Standalone run and in-memory-only objects
Next Topic:[Teneo]Problems when deleting object
Goto Forum:
  


Current Time: Wed Aug 17 21:56:15 GMT 2022

Powered by FUDForum. Page generated in 0.01799 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top