Just struggling with a multi-template XSLT script. I have an XSLT script which loops and creates a table of data, but I want each item at level 3 to render in a different table template to items at level 4.
I've got the first template working (so at the moment, the same table structure is just nested) but need a kick-start to know how to get it to render a different template when at level 4:
So it's basically putting the stuff at level 3 in one kind of HTML table, then nesting the level 4 content in a completely different configuration of HTML table.
Alternative XSLT template
Hi,
Just struggling with a multi-template XSLT script. I have an XSLT script which loops and creates a table of data, but I want each item at level 3 to render in a different table template to items at level 4.
I've got the first template working (so at the moment, the same table structure is just nested) but need a kick-start to know how to get it to render a different template when at level 4:
Can anyone show basically how to do this, as I can't get my brain around it?
Thanks!
Hi Dan,
Have you got an example of the HTML you want to produce? (I started writing an answer, but then realised that I might be going off on a tangent!)
Cheers, Lee.
What I'm actually trying to produce is pretty convoluted, but something which would set me going would be like this:
So it's basically putting the stuff at level 3 in one kind of HTML table, then nesting the level 4 content in a completely different configuration of HTML table.
Make sense?
Hi Dan,
OK... get ready for this... it's going to blow your mind! haha
OK, there are a lot of templates here - following the logic it should like this...
The first template selects @level=2, then apply-templates to one level below that (@level=3).
Next @level3 is rendered as a <table>, then <tr>, then the <td> (with empty <td>, watch out for XML rendering i.e. <td/>).
The "row" template then apply-templates for any child nodes (@level=4) with the "row_colspan" template - which then renders the "cell" templates.
I haven't tested this, but worked through the logic and it "should" work. Have I blown your mind? (I've gone cross-eyed!)
Cheers, Lee.
Nice one, thanks Lee. Yep, that's done it though. My head is now well and truly frazzled! Even more well and truly frazzled you might say :)
Before I even try to get into this, it's giving me a pretty high level error:
Any ideas?
Opps! My bad - I went a bit copy-n-paste crazy! ... change the "name" attribute to "match" on the <xsl:templates>
Cheers, Lee.
Now that last part actually does make sense, thanks.
Lee you're an absolute XSLT legend. Works a treat. Thanks so much, and have a top weekend.
Awesome! Glad that it works. Enjoy the weekend too... hopefully it wont rain too much! (in Bristol) :-$
is working on a reply...