gpt4 book ai didi

xslt - 如何对XSLT模板的输出进行第二次转换

转载 作者:行者123 更新时间:2023-12-03 14:42:39 25 4
gpt4 key购买 nike

我只有基本的XSLT技能,所以如果这是基本的或不可能的,我深表歉意。

我有一个分页模板,该模板可在我正在查看的网站上使用。有一个错误,一个特定的搜索需要在页面链接的href上附加一个categoryId参数。我无法更改分页器样式表,否则我只会为其添加参数。我想做的是照原样应用模板,然后根据其输出进行第二次转换。这可能吗?其他人通常如何扩展库模板?

到目前为止,我已经考虑过对输出进行递归复制,并在处理href时将模板应用于href。这样做的语法让我有些措手不及,特别是因为我什至不确定它是否可行。



编辑-在达布勒的答案和迈克尔·凯的评论之间,我们到了那里。这是我的完整测试。

 <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, '&amp;', '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 2中是可能的。您可以将数据存储在变量中,然后在该变量上调用apply-templates。

基本示例:

<xsl:variable name="MyVar">
<xsl:element name="Elem"/> <!-- Or anything that creates some output -->
</xsl:variable>
<xsl:apply-templates select="$MyVar"/>


在样式表中的某处有一个与Elem相匹配的模板。您还可以使用单独的模式来在两个阶段之间保持清晰的区分(构建变量并对其进行处理),尤其是当两个阶段都使用匹配相同节点的模板时。

关于xslt - 如何对XSLT模板的输出进行第二次转换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7635593/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com