How to transform a xml into a html with the xml tags and attributes as text of a html with equivalent tree, using XSLT?



I think I never asked a question with such an incomprehensible title, sorry about that.


Let say the XML file I have look like that (not that I don't want to copy/paste, but it's too big):



<A attr1="aaa" attr2="bbb">
<B attr8="23156">
<C attr10="bla"/>
<C attr10="bli"/>
<C attr10="blo"/>
</B>
</A>
<A attr1="jhg" attr2="ygyug">
<B attr8="126">
<C attr10="bla"/>
</B>
<B attr8="102">
<C attr10="bla"/>
<C attr10="blo"/>
</B>
</A>


Well, you got the point, a generic XML file. I don't know the tags, the tags order, and the attributes. I have to use XSLT to turn this XML into a HTML file with all the "nodes" and attributes of the xml as text, in an equivalent tree :



<div>
&lt;A attr1="aaa" attr2="bbb"&gt;
<div>
&lt;B attr8="23156"&gt;
<div>&lt;C attr10="bla"/&gt;</div>
<div>&lt;C attr10="bli"/&gt;</div>
<div>&lt;C attr10="blo"/&gt;</div>
</div>
</div>
<div>
&lt;A attr1="jhg" attr2="ygyug"&gt;
<div>
&lt;B attr8="126"&gt;
<div>&lt;C attr10="bla"/&gt;</div>
</div>
<div>
&lt;B attr8="102"&gt;
<div>&lt;C attr10="bla"/&gt;</div>
<div>&lt;C attr10="blo"/&gt;</div>
</div>
</div>


I can get every nodes' name by selecting //node(), I can get attributes by selecting @*, but I can't figure out how to get the html as expected.


Any help you can give will be greatly appreciated :D


No comments:

Post a Comment