I have an xml file with 000’s of lines with elements that differ only by some sub-string that appears in various attributes and element content.
So i’ll like to ‘condense’ the xml and have a stylesheet create xml on the fly by substituting known sub-strings at runtime with known substitutions.
A stylesheet approach would seem to be the elegant solution to this problem given what i’ve read about them, but if it works i really don’t mind how i get a solution.
This principal would need to be generic i.e apply to xml elements with child nodes ‘n levels deep’
eg
‘condensed’ xml could look like
<element id="11[substitute here]11">
<name>[substitute here]</name>
<settings>
<setting>
<name>[substitute here]Setting</name>
<!-- could be more elements here, n levels deep -->
</setting>
</settings>
<moreConfig>zz[substitute here]zz</moreConfig>
</element>
expanded xml, substituting ‘[substitute here]’ with ‘aaa’ and then ‘bbb’, would then look like
<element id="11aaa11">
<name>aaa</name>
<settings>
<setting>
<name>aaaSetting</name>
<!-- could more elements here, n levels deep -->
</setting>
</settings>
<moreConfig>zzaaazz</moreConfig>
</element>
<element id="11bbb11">
<name>bbb</name>
<settings>
<setting>
<name>bbbSetting</name>
<!-- could more elements here, n levels deep -->
</setting>
</settings>
<calendar>zzbbbzz</calendar>
</element>
I’m doing this in java 6, so my understanding is if using xsl only 1.0 is supported.
Hope i’ve outlined the problem clearly, appreciate any help!
many thanks
This transformation:
when applied on the provided XML document:
produces the wanted, correct result: