XML to XML with XSLT

Here should go questions about transforming XML with XSLT and FOP.
opelk
Posts: 1

XML to XML with XSLT

Mon Feb 23, 2009 7:11 pm

Hi,

I have a xml file with following structur:

<XML>
<MODELS>
<MODEL>
<AttributesBig>
<Instance>
<Attributes>
<Connection>

I want to transform it into this structur:



<XMI.content>
<UML:Model>
<UML:Namespace.ownedElement>
<UML:Package>
<UML:Namespace.ownedElement>
<UML:Model >
<UML:Namespace.ownedElement>
<UML:Actor>
</UML:Actor>
<UML:UseCase>
</UML:UseCase>
<UML:Comment>
<UML:ModelElement.name>
</UML:ModelElement.name>
<UML:Comment.body>
</UML:Comment.body>
<UML:Comment.annotatedElement>
</UML:Comment.annotatedElement>
</UML:Comment>


<UML:Association xmi.id = 'B'
name = '{Test}' visibility = 'package' isSpecification = 'false'
isAbstract = 'false' stereotype = 'XX.11'>
<UML:Association.connection>
<UML:AssociationEnd xmi.id = 'C' visibility = 'public' isSpecification = 'false'
isNavigable = 'false' aggregation = 'none'
targetScope = 'instance' changeability = 'changeable'>
<UML:AssociationEnd.multiplicity>
<UML:Multiplicity/>
</UML:AssociationEnd.multiplicity>
<UML:AssociationEnd.participant>
<UML:Classifier xmi.idref = 'D'/>
</UML:AssociationEnd.participant>
</UML:AssociationEnd>
<UML:AssociationEnd xmi.id = 'E' visibility = 'public' isSpecification = 'false'
isNavigable = 'false' aggregation = 'none'
targetScope = 'instance' changeability = 'changeable'>
<UML:AssociationEnd.multiplicity>
<UML:Multiplicity/>
</UML:AssociationEnd.multiplicity>
<UML:AssociationEnd.participant>
<UML:Classifier xmi.idref = 'F'/>
</UML:AssociationEnd.participant>
</UML:AssociationEnd>
</UML:Association.connection>
</UML:Association>

</UML:Namespace.ownedElement>
</UML:Model>
<UML:TaggedValue xmi.id = 'XX.9'
name = 'text'
modelElement = 'XX.7'>
<UML:TaggedValue.dataValue>

</UML:TaggedValue.dataValue>
</UML:TaggedValue>
</XMI.content>
</XMI>

So, I have the problem now, that I need information in <UML:Association> (target file) <Connection> and <Instance> (both start-file) and Im not able tor search with for


<XMI>
<XMI.content>
<xsl:for-each select="MODELS">
<xsl:variable name="VarMODELS" select="."/>
<UML:Model>
<UML:Namespace.ownedElement>
<UML:Package>
<UML:Namespace.ownedElement>
<xsl:for-each select="MODEL">
<xsl:variable name="VarMODEL" select="."/>
<UML:Model>
<UML:Namespace.ownedElement>
<xsl:for-each select="INSTANCE">
<xsl:choose>
<xsl:when test="@class='actor'">
<UML:Actor>
<xsl:attribute name="xmi.id" separator=" ">
<xsl:value-of select="@id"/>
</xsl:attribute>
</UML:Actor>
</xsl:when>
<xsl:when test="@class='use case'">
<UML:UseCase>
<xsl:attribute name="xmi.id" separator=" ">
<xsl:value-of select="@id"/>
</xsl:attribute>
</UML:UseCase>
</xsl:when>
<xsl:when test="@class='Note'">
<UML:Comment>
</UML:Comment>
</xsl:when>
<xsl:when test="@class='system boundary'">
<UML:system_boundary>
</UML:system_boundary>
</xsl:when>
</xsl:choose>
</xsl:for-each>


<xsl:for-each select="CONNECTOR">
<xsl:choose>
<xsl:when test="@class='communicates'">
<UML:Association>
<xsl:attribute name="xmi.id" separator=" ">
<xsl:value-of select="@id"/>
</xsl:attribute>

<UML:Association.connection>


<UML:AssociationEnd visibility='public' isSpecification="false" isNavigable="false" aggregation="none" targetScope="instance" changeability="changeable">


<xsl:variable name="VarClass" select="FROM/@class"/>
<xsl:variable name="VarName" select="FROM/@instance"/>
<xsl:for-each select="INSTANCE">
<xsl:if test="@class=$VarClass">
<xsl:if test="@name=$VarName">

<xsl:value-of select="@id"/>
</xsl:if>
</xsl:if>
</xsl:for-each>

<UML:AssociationEnd.multiplicity>
<UML:Multiplicity/>
</UML:AssociationEnd.multiplicity>
<UML:AssociationEnd.participant>
<UML:Classifier xmi.idref="S.11"/>
</UML:AssociationEnd.participant>
</UML:AssociationEnd>

<UML:AssociationEnd xmi.id="G.19" visibility="public" isSpecification="false" isNavigable="false" aggregation="none"
</UML:AssociationEnd>
</UML:Association.connection>
</UML:Association>
</xsl:when>
</xsl:choose>
</xsl:for-each>

</UML:Namespace.ownedElement>
</UML:Model>
</xsl:for-each>
</UML:Namespace.ownedElement>
</UML:Package>
</UML:Namespace.ownedElement>
</UML:Model>
</xsl:for-each>
</XMI.content>
</XMI>

The interesting postion in the code I make bold. So I must compare some attributes of <connectors> to some attributes of <INSTANCE> and if this information the same i must put an other attribute of <Intstance> to the target file as a attribut. My question is, how can I realize that.

THX

Opelk

Return to “XSLT and FOP”

Who is online

Users browsing this forum: No registered users and 0 guests