How to rename the elements according to a mapping table based on attribute's of the element?
Any suggestions would be much appreciated.
Maybe a XSLT 2.0 template and modifying the mapping table for better solution?
Many thanks in advance
Thomas
Original XML:
<transaction>
<records type="1" >
<record type="1" >
<field number="1" >
<item>223</item>
</field>
<field number="2" >
<item>456</item>
</field>
</record>
</records>
<records type="14" >
<record type="14" >
<field number="1" >
<item>777</item>
</field>
<field number="2" >
<item>678</item>
</field>
</record>
<record type="14" >
<field number="1" >
<item>555</item>
</field>
</record>
</records>
</transaction>
Mapping table:
<xsl:stylesheet>
<mapping type="1" from="record" to="first-record">
<map number="1" from="field" to="great-field"/>
<map number="2" from="field" to="good-field"/>
</mapping>
<mapping type="14" from="record" to="real-record">
<map number="1" from="field" to="my-field"/>
<map number="2" from="field" to="other-field"/>
</mapping>
</xsl:stylesheet>
Result after the transformation:
<transaction>
<records type="1" >
<first-record type="1" >
<great-field number="1" >
<item >223</item>
</great-field>
<good-field number="2" >
<item >456</item>
</good-field>
</first-record>
</records>
<records type="14" >
<real-record type="14" >
<my-field number="1" >
<item >777</item>
</my-field>
<other-field number="2" >
<item >678</item>
</other-field>
</real-record>
<real-record type="14" >
<my-field number="1" >
<item >555</item>
</my-field>
</real-record>
</records>
</transaction>
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…