dimanche 19 avril 2015

XSL-T Adding Missing schema elements from input xml as empty tags


Vote count:

0




I am relatively new to XSL-T. My requirement is rather simple. I want to add missing elements of Schema which are not present in the xml as empty tags.


For example,



<xs:schema xmlns:xs="http://ift.tt/tphNwY"
attributeFormDefault="unqualified"
elementFormDefault="qualified">
<xs:element name="RootElement">
<xs:complexType>
<xs:sequence>
<xs:element name="XMLTagOne">
<xs:complexType>
<xs:sequence>
<xs:element type="xs:string" name="value1"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="RepeatableElementOne" maxOccurs="unbounded" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element type="xs:string" name="value2"/>
<xs:element name="RepeatableElemenTwo" maxOccurs="unbounded" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element type="xs:string" name="value3"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>


Consider This i/p:



<RootElement>
<RepeatableElementOne>
<value2>bb</value2>
<RepeatableElemenTwo>
<value3>cc</value3>
</RepeatableElemenTwo>
<RepeatableElemenTwo>
<value3>dd</value3>
</RepeatableElemenTwo>
</RepeatableElementOne>
<RepeatableElementOne>
<value2>ee</value2>
</RepeatableElementOne>
</RootElement>


For this i/p I want the element <XMLTagOne> and <RepeatableElemenTwo> to be added as empty tags.


Expected O/P:



<RootElement>
<XMLTagOne> <!-- Added as empty tag though not present in i/p-->
<value1></value1>
</XMLTagOne>
<RepeatableElementOne>
<value2>bb</value2>
<RepeatableElemenTwo>
<value3>cc</value3>
</RepeatableElemenTwo>
<RepeatableElemenTwo>
<value3>dd</value3>
</RepeatableElemenTwo>
</RepeatableElementOne>
<RepeatableElementOne>
<value2>ee</value2>
<RepeatableElemenTwo>
<value3></value3>
</RepeatableElemenTwo>
</RepeatableElementOne>
</RootElement>


With Some Initial Research I discovered that I have to traverse through every node with an identity template matching all elements. Can you suggest me how I can approach this problem? Thanks.



asked 1 min ago







XSL-T Adding Missing schema elements from input xml as empty tags

Aucun commentaire:

Enregistrer un commentaire