【发布时间】:2011-10-03 13:24:23
【问题描述】:
我只有基本的 XSLT 技能,如果这是基本的或不可能的,敬请见谅。
我有一个分页器模板,它在我正在查看的网站上随处使用。存在一个错误,其中一个特定搜索需要将 categoryId 参数附加到页面链接的 href。 我无法更改分页器样式表,否则我只会为其添加一个参数。我想做的是按原样应用模板,然后根据其输出进行第二次转换。这可能吗?其他人通常如何扩展库模板?
到目前为止,我一直在考虑对输出进行递归复制,并在处理 href 时将模板应用于它们。它的语法让我有些不知所措,特别是因为我什至不确定它是否可能。
编辑 - 在 Dabbler 的回答和 Michael Kay 的评论之间,我们到达了那里。这是我的完整测试。
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:ext="http://exslt.org/common">
<!-- note we require the extensions for this transform -->
<!--We call the template to be extended here and store the result in a variable-->
<xsl:variable name="output1">
<xsl:call-template name="pass1"/>
</xsl:variable>
<!--The template to be extended-->
<xsl:template name="pass1">
<a href="url?param1=junk">foo</a>
</xsl:template>
<!--the second pass. we lock this down to a mode so we can control when it is applied-->
<xsl:template match="a" mode="pass2">
<xsl:variable name="href" select="concat(@href, '&', 'catid', '=', 'stuff')"/>
<a href="{$href}"><xsl:value-of select="."/></a>
</xsl:template>
<xsl:template match="/">
<html><head></head><body>
<!--the node-set extension function turns the first pass back into a node set-->
<xsl:apply-templates select="ext:node-set($output1)" mode="pass2"/>
</body></html>
</xsl:template>
</xsl:stylesheet>
【问题讨论】:
标签: xslt