I am writing an application that will modify existing menu output. I have a number of ways I can think of to do this, one of them I think is XSLT but I am a complete beginner in such transforms.
I am looking to change the following:
<ul>
<li><a href="#">Item1</a>
<ul>
<li class="featured"><a href="#">Item 1.1</a></li>
<li><a href="#">Item 1.2</a></li>
<li class="featured"><a href="">Item 1.3</a></li>
<li><a href="#">Item 1.4</a></li>
</ul>
</li>
</ul>
To the new:
<ul>
<li><a href="#">Item1</a>
<ul>
<li>
<ul>
<li><a href="#">Item 1.1</a></li>
<li><a href="#">Item 1.2</a></li>
<li><a href="#">Item 1.3</a></li>
<li><a href="#">Item 1.4</a></li>
</ul>
</li>
<li>
<ul class="featured">
<li><a href="#">Item 1.1</a></li>
<li><a href="#">Item 1.3</a></li>
</ul>
</li>
</ul>
</li>
</ul>
I have the following questions:
What transform would I need for the above?
How would I constrain to only n-levels deep (in this case we would not want children of the ul.ul.ul.li
items, i.e. Item x.x, to be included)?
What if I wanted to only apply this transform to a style where the top <ul>
has an attribute class="style1"
, and if it is set to "style2"
a different transform is applied?
You can try this XSLT
If you face any problem please let me know.
I'm not 100% sure why you are adding an extra level of
ul
and I'm not sure about the "n-levels" deep requirement (a better example would help), but this should get you started:XSLT 1.0
Output