XSL - Is there a way I can make this template reusable?
XSL noob here :-)
I've got the following template which is being used to produce a dropdown for my ANT script.
<!-- Dropdown templates -->
<xsl:template name="componentDropdown">
<xsl:text>trunk</xsl:text>
<!-- Branch Data -->
<xsl:for-each select="document('../../../temp/components_branches.xml')/lists/list/entry">
<xsl:sort select="commit/@revision" order="descending" />
<xsl:text>;branches/</xsl:text>
<xsl:value-of select="name" />
</xsl:for-each>
<!-- Tag Data -->
<xsl:for-each select="document('../../../temp/components_tags.xml')/lists/list/entry">
<xsl:sort select="commit/@revision" order="descending" />
<xsl:if test="name != 'archive'">
<xsl:text>;tags/</xsl:text>
<xsl:value-of select="name" />
</xsl:if>
</xsl:for-each>
</xsl:template>
The thing is that I've got this three times over - cut & paste job - all the same but the reference to "components" is being swapped for "plugins" and "website". We've got a few more ANT scripts I'd like to migrate to this as well so ideally I'd like this as a reusable function-based template of some kind.
Working in progress but I've currently got the following:-
<xsl:template name="dropdown">
<xsl:param name="type">website</xsl:param>
<xsl:param name="path"></xsl:param>
<!-- Branch Data -->
<xsl:text><xsl:value-of select="$path" /></xsl:text>
<xsl:for-each select="document(concat('../../../temp/{$type}_tags.xml',''))/lists/list/entry">
<xsl:sort select="commit/@revision" order="descending" />
<xsl:text>;branches/</xsl:text>
<xsl:value-of select="name" />
</xsl:for-each>
</xsl:template>
The issue seems to be getting the documnet() function to accept dynamic variables.
Only other thing I can say is the XSL is declared as 1.0. I don't kno开发者_开发技巧w if that makes a difference but any pointers are appreciated :).
Cheers, James
To make document()
works properly, you need to concatenate as follows:
document(concat('../../../temp/',$type,'_tags.xml',''))
精彩评论