You can use template similar to using function in programming language. simply define a template with name attribute set. use <xsl:call-template> to call the template
The as attribute specifies the return of the function
set a template:
<xsl:template name="TemplateName">
<!-- The template content goes here. -->
</xsl:template>
call a template:
<xsl:call-template name=" TemplateName" />