XSL is based on templating.
XML data can be "re-used" at three-levels. At the most basic level you can <xsl:for-each />
through XML.
Note: For-each in XSL is not looping through the data, it's just matching the data. Also when your "inside" a for-each your inside that "context" of the XML (which is like the concept of "scope" in programming)
An example of using and re-using a for-each
<xsl:for-each select="/xml/data/here">
... do some stuff ...
</xsl:for-each>
<xsl:for-each select="/xml/data/here">
... do some DIFFERENT stuff ...
</xsl:for-each>
The for-each nodes are contained within template nodes (2nd level of reuse). There are two types of template nodes: Match and Named. Match template nodes, act like the for-each node mentioned above, but are automatically called by the template engine if any nodes are matched when XSL processing starts. Match template nodes can also be explicitly applied. On the other hand Named template nodes are always explicitly applied and can be thought of as like functions.
Example of a Match template which will Always be called (because a root node will always exist)
<xsl:template match="/">
... do some stuff ...
</xsl:template>
A Match template calling another match template explicitly
<xsl:template match="/">
<xsl:apply-templates select="xml/data/too" />
</xsl:template>
<xsl:template match="xml/data/too">
... do something ...
</xsl:template>
Note: In order for the Match template to work, the XML Node it is matching needs to exist. If it doesn't there is no match, so that template is not called.
Example of a Named template
<xsl:template name="WriteOut">
... data with NO Context Here ...
</xsl:template>
Or calling a Named template from a Matched template
<xsl:template match="/">
<xsl:call-template name="WriteOut" />
<xsl:template>
Note: You can mix and match where you call matched and named templates from, you just have to watch what context you are in.
All of template nodes are held in XSL Stylesheets, and you can include and import various stylesheets. For example you can hold all of the templates dealing with HTML header nodes in one template and all of the templates dealing with the HTML body nodes in another. Then you can create one stylesheet that includes both Header and Body stylesheets.
Example of an include node
<xsl:include href="header.xsl" />
In conclusion there are three ways to abstracting chunks of data, through for-eaching, through templating or through including stylesheets.