Quantcast
Channel: XML, System.Xml, MSXML and XmlLite forum
Viewing all articles
Browse latest Browse all 935

Generic XSLT transformation code

$
0
0

I've got quite some challenge in here...

Is it possible to have an XSL code that will apply to whatever hierarchy of XML, to transform it into nested HTML list?

Example XML:

<Base><Parent><Child/><Child/><Child><ChildOne/><ChildOne/><ChildOne><ChildTwo/><ChildTwo/></ChildOne></Child></Parent><Parent><Child><ChildOne><ChildTwo><ChildThree><ChildFour/></ChildThree><ChildThree/></ChildTwo></ChildOne><ChildOne/><ChildOne/></Child><Child/><Child/></Parent></Base>

Desired result:

<ul><li>Parent1<ul><li>Child</li><li>Child<ul><li>ChildOne</li><li>ChildOne><ul><li>ChildTwo</li><li>ChildTwo</li></ul></li></ul></li></ul></li><li>Parent2<ul><li>Child<ul><li>ChildOne<ul><li>ChildTwo<ul><li>ChildThree<ul><li>ChildFour</li></ul></li><li>ChildThree</li></ul></li></ul></li><li>ChildOne</li><li>ChildOne</li></ul></li><li>Child</li></ul></li></ul>

So the logic is that if there is other elements(suppressed el.) under an element(upper el.) - the suppressed el. get surround by <li>name of upper el.<ul>all suppressed el.</ul></li>and so on.

My point is that this XSL code works not by values or names of elements or attributes, but by condition checking, if there are other elements falling under a particular element.

F.e., if ChildThree didn't have ChildFour under itself, it would just be <li>ChildThree> instead of

<li>ChildThree<ul><li>ChildFour</li></ul></li>

Hope I explained myself clear. :)

P.S. This is how it has to look in the browser, more or less (just to give visual representation, as we humans like to see the things. :P )



Viewing all articles
Browse latest Browse all 935

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>