I have the following elements in my xmi file:
<element1 id= 3 >
<element2 id= 3>
I want to transform them into something like:
<element1 id= 3 name =element2>
<element2 id= 3>
I am using xslt to transform:
<xsl:if test="@id = //*[@id]/@id">
<xsl:sequence
select="fn:createAtt('name',X)" />
</xsl:if>
I want to compare the id of two elements and in case they match then i want to save the name of second element (element2) into the name attribute of first element.
The comparison works ok. The problem is how to read the name of the second element ? I tried to use the name() function but am not able to read exactly that name that matches the comparison.
I would do it like this: first define a key as
then I would write a template
That way you can efficiently reference the elements using a key, then if one element of the same id is found the attribute named
nameis created. I used the XSLT/XPath 2.0node-namefunction, depending on your exact requirements you might want to use<xsl:attribute name="name" select="name($same-id[1])"/>instead.