Hi all, My xslt will make a different bakcolor to some some output elements according to an <restaurnat>order in an XML, whether it is odd number or it is even number, here is my xml file outline <restaurants> <restaurant> .... </restaurant> ... <restaurant> ... </restaurant> </restaurants> I can use <xsl:template match="restaurant[position()mod 2=1]"> or <xsl:template match="restaurant[position()mod 2=0]"> to apply a different templates, but much of the content in these two templates are same except the background color , so I think is it possible to use a method like a function call to finish the work. Clara -- thank you so much for your help
clara wrote: > I can use <xsl:template match="restaurant[position()mod 2=1]"> or > <xsl:template match="restaurant[position()mod 2=0]"> to apply a different > templates, but much of the content in these two templates are same except the > background color , so I think is it possible to use a method like a function > call to > finish the work. You have a couple of options, with XSLT 2.0 you can do <xsl:next-match/> see <URL:http://www.w3.org/TR/xslt20/#apply-imports> to apply the next matching template. With both XSLT 1.0 and 2.0 you can use <xsl:apply-imports/> to apply a template with a lower priority that has been imported. Then in XSLT 2.0 you can indeed implement your own functions with xsl:function. And in both XSLT 1.0 and 2.0 you can write named templates and call them with xsl:call-template. -- Martin Honnen --- MVP XML http://JavaScript.FAQTs.com/
clara wrote: > Hi all, > > My xslt will make a different bakcolor to some some output elements > according to an <restaurnat>order in an XML, whether it is odd number or it > is even number, here is my xml file outline > > <restaurants> > <restaurant> > .... > </restaurant> > ... > <restaurant> > ... > </restaurant> > > </restaurants> > > I can use <xsl:template match="restaurant[position()mod 2=1]"> or > <xsl:template match="restaurant[position()mod 2=0]"> to apply a different > templates, but much of the content in these two templates are same except the > background color , so I think is it possible to use a method like a function > call to finish the work. Possibly, but this is a FAQ. See the XSL FAQ at http://www.dpawson.co.uk/xsl/rev2/matching.html#d17314e186 ///Peter -- XML FAQ: http://xml.silmaril.ie/