Jump to content

Xml To Xml With Xslt


Guest opelk
 Share

Recommended Posts

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.THXOpelk

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...