gpt4 book ai didi

xml - XSLT 调用模板名称属性

转载 作者:行者123 更新时间:2023-12-03 16:45:56 24 4
gpt4 key购买 nike

好像我不能在 call-template 元素的 name 属性中使用 Xpath。我怎样才能解决这个问题?任何帮助/想法都会很棒!

<xsl:for-each select="child::knomaddb/Content/Videos">
<xsl:result-document method="xhtml" href="{local-name()}.html">
<html>
<body>
<h1>Knomad</h1>
<h2>{local-name()} Videos</h2>
<table border="1">
<tr bgcolor="#9acd32">
<th>Title</th>
<th>Video</th>
<th>Description</th>
<th>Comments</th>
</tr>
<xsl:for-each select="Video">
<xsl:call-template name="{ancestor::local-name()}"/>
</xsl:for-each>
</table>
</body>
</html>
</xsl:result-document>
</xsl:for-each>

最佳答案

It seems as if I cant use an Xpath in the name attribute of the call-template element. How can I get around this?



好问题,+1。

你不能。但你可以改用 <xsl:apply-templates> .

这是一个快速演示:
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:double="double" xmlns:incr="incr" xmlns:my="my:my"
exclude-result-prefixes="double incr my"
>
<xsl:output method="text"/>

<double:double/>
<incr:incr/>

<xsl:variable name="vFuncDouble"
select="document('')/*/double:*[1]"/>

<xsl:variable name="vFuncIncr"
select="document('')/*/incr:*[1]"/>

<xsl:function name="my:double">
<xsl:param name="arg1" />

<xsl:sequence select="2*$arg1"/>
</xsl:function>

<xsl:function name="my:incr">
<xsl:param name="arg1" />

<xsl:sequence select="1+$arg1"/>
</xsl:function>

<xsl:template name="double" match="double:*">
<xsl:param name="arg1"/>

<xsl:sequence select="my:double($arg1)"/>
</xsl:template>

<xsl:template name="incr" match="incr:*">
<xsl:param name="arg1"/>

<xsl:sequence select="my:incr($arg1)"/>
</xsl:template>

<xsl:function name="my:apply">
<xsl:param name="pFun" as="element()"/>
<xsl:param name="arg1"/>

<xsl:apply-templates select="$pFun">
<xsl:with-param name="arg1" select="$arg1"/>
</xsl:apply-templates>
</xsl:function>

<xsl:template match="/">
<xsl:sequence select="my:apply($vFuncIncr, my:apply($vFuncDouble,2))"/>
</xsl:template>
</xsl:stylesheet>

当将此转换应用于任何 XML 文档(未使用)时,将产生所需的结果:
5

请注意 :

可以作为参数(第一个参数)传递给 my:apply()任何“功能”和 my:apply()将其应用于第二个参数。

使用相同的原理 the FXSL library 在 XSLT 1.0 和 XSLT 2.0 中实现了高阶函数 (HOF) -- read more here .

在即将发布的 XPath 3.0 函数首次成为 中的第一类对象Xpath Data Model (XDM)。

关于xml - XSLT 调用模板名称属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8362919/

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