I would like to simplify some of my xslt. I think I can do that with call-template... or apply-templates...? Well, I'm a little confused here.
My idea is that first I get the node, witch contains the data I need to view. (the presentation of the data is setup in tabs) Then I think it could be nice if I first had the basic code for the tabs. In a tab there should be a call-template/apply-templates that gets the content for the tab.
In my mind it should look something like this:
<xsl:template match="/"> <div id="tabPanes"> <div id="tabPane1"> <xsl:call-template name="tab1"/> </div> <div id="tabPane2"> <xsl:call-template name="tab2"/> </div> </div> </xsl:template> <xsl:template name="tab1"> <h1>This is the content of tab 1</h1> <p> <xsl:value-of select="content1"/> </p> </xsl:template> <xsl:template name="tab2"> <h1>This is the content of tab 2</h1> <p> <xsl:value-of select="content2"/> </p> </xsl:template>
But don't really know how to do it and my experiments has failed until now.
Ideally you should use apply-templates when you have a node-set to apply a template against, and call-template when you have a template that you need to use, but doesn't match a node-set.
My goal for this is to present the content the particular node in a way that is easy for the end-user to read. I think I have achieved that be designing and viewing it in tabs (e.g. "Introduction", "Facts", "Transport", "Media" and so on).
But my current xslt code to get the result I want is very long and sometimes complicated. So am wondering if there is a way to make my xslt more easy to develop - and here my thought is that "slicing" the code might be the solution.
But am I wrong? Is it "not go" to use call-template or apply-templates to reach my goal here?
I think you should use a template if you would wind up calling/applying it more than once, i.e. if it simplifies the code and reduces repetition. Otherwise your code will be just as long, but a little more comlicated.
Hi, I don't read whole question, but try look at this presentation, he recomend apply templates (and know xslt well :-) http://pimpmyxslt.com/presentations/
I have now made some changes in my xslt code, so it mahces my idea - and it works; I get the result I want... But is it okay or is it bad practice?
<xsl:template match="/"> <!--I HAVE SIMPLIFIED THIS CODE - IT'S NOT THE TOPIC--> <xsl:apply-templates select="$root//NodeType[Exslt.ExsltStrings:lowercase(@nodeName) = $qs]" /> </xsl:template>
Bad practice? Nah, I don't think so... there are probably ways to make it a little more re-usable - but that depends on if each of your tabs hold the same HTML mark-up.
I notice on "pane4" has its own ID ... so that's unique to that? Unless you want all the "panes" to have their own ID?
There are many ways to do it. If you want some examples, feel free to post your entire XSLT and we'll do a little refactoring? (all in the sake of XSLT "fun" LOL!)
Use call-template or apply-templates?
I would like to simplify some of my xslt. I think I can do that with call-template... or apply-templates...? Well, I'm a little confused here.
My idea is that first I get the node, witch contains the data I need to view. (the presentation of the data is setup in tabs) Then I think it could be nice if I first had the basic code for the tabs. In a tab there should be a call-template/apply-templates that gets the content for the tab.
In my mind it should look something like this:
But don't really know how to do it and my experiments has failed until now.
Hi Webspas,
Ideally you should use apply-templates when you have a node-set to apply a template against, and call-template when you have a template that you need to use, but doesn't match a node-set.
There's a good explanation on StackOverflow about it: http://stackoverflow.com/questions/84422/xslt-performance-call-template-vs-apply-template
Not sure how your example XSLT is related to Umbraco, but if there is anything specific that you want to do, then let us know!
Cheers, Lee.
My goal for this is to present the content the particular node in a way that is easy for the end-user to read. I think I have achieved that be designing and viewing it in tabs (e.g. "Introduction", "Facts", "Transport", "Media" and so on).
But my current xslt code to get the result I want is very long and sometimes complicated. So am wondering if there is a way to make my xslt more easy to develop - and here my thought is that "slicing" the code might be the solution.
But am I wrong? Is it "not go" to use call-template or apply-templates to reach my goal here?
I think you should use a template if you would wind up calling/applying it more than once, i.e. if it simplifies the code and reduces repetition. Otherwise your code will be just as long, but a little more comlicated.
Hi, I don't read whole question, but try look at this presentation, he recomend apply templates (and know xslt well :-)
http://pimpmyxslt.com/presentations/
Petr
I have now made some changes in my xslt code, so it mahces my idea - and it works; I get the result I want... But is it okay or is it bad practice?
Hey Webspas,
Bad practice? Nah, I don't think so... there are probably ways to make it a little more re-usable - but that depends on if each of your tabs hold the same HTML mark-up.
I notice on "pane4" has its own ID ... so that's unique to that? Unless you want all the "panes" to have their own ID?
There are many ways to do it. If you want some examples, feel free to post your entire XSLT and we'll do a little refactoring? (all in the sake of XSLT "fun" LOL!)
Cheers, Lee.
Okay... you asked for it ;-)
* Some of the text has been modifired.
Whoah! LOL! Had a quick look over it... each of the panes are quite unique - so I reckon that you are doing it the right way! :-)
Cheers, Lee.
haha... Well, thanks Lee
is working on a reply...