I am relatively new to XSLT and i am working on a project involving xml and xslt1.0.
I have a xml code (simplified version) that looks like
<visualChildren>
<object class="com.zerog.ia.installer.InstallSet" >
<installChildren>
<object class="com.zerog.ia.installer.InstallBundle" objectID="33110emc908m">
<property></property>
</object>
<object class="com.zerog.ia.installer.InstallBundle" objectID="43110emc9667m">
<property></property>
</object>
</installChildren>
</object>
</visualChildren>
I would need to collect all the object ids iteratively and store as
<object RefId={ObjectId} />
under visualChildren. Expected result is
<visualChildren>
<object class="com.zerog.ia.installer.InstallSet" >
<installChildren>
<object class="com.zerog.ia.installer.InstallBundle" objectID="33110emc908m">
<property></property>
</object>
<object class="com.zerog.ia.installer.InstallBundle" objectID="43110emc9667m">
<property></property>
</object>
</installChildren>
</object>
<object RefId=33110emc908m />
<object RefId=43110emc9667m />
</visualChildren>
Could anyone help me to achieve this with xslt 1.0
You can modify the identity transformation to copy over everything exactly except for the
visualChildren/object
elements, which can be copied over as-is plus theRefId
attribute you request:Applying the above XSLT to your input XML:
Yields the following output XML:
As requested.
Note: Should you want all of the
@objectID
attributes below a givenvisualChildren/object
element rather than all of the@objectID
attributes in the entire document, then changeto