Ureader.com  
Microsoft software help and Community
   home   |   control panel login   |   archive   |  
 
XML
data.xmlanalysis
mappoint.webservice
msf
msxml-webrelease
netmyservices.sdk
passport.sdk
soap
soapsdk
uddi.general
uddi.programming
uddi.specification
xml
xmlsqlwebrelease
xsl
  
 
date: Mon, 21 Apr 2008 10:13:02 -0700,    group: microsoft.public.xml        back       


how to make a "Function" in XSLT   
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
date: Mon, 21 Apr 2008 10:13:02 -0700   author:   clara

Re: how to make a "Function" in XSLT   
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/
date: Mon, 21 Apr 2008 19:34:25 +0200   author:   Martin Honnen

Re: how to make a "Function" in XSLT   
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/
date: Mon, 21 Apr 2008 19:26:02 +0100   author:   Peter Flynn

Google
 
Web ureader.com


    COPYRIGHT 2007, YARDI TECHNOLOGY LIMITED, ALL RIGHT RESERVE  |   contact us