似乎不能在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>发布于 2011-12-03 06:01:19
似乎不能在call-template元素的name属性中使用Xpath。我怎么才能避免这个问题呢?
问得好,+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>当对任何文档(未使用)应用此转换时,将产生所需的结果:
5请注意:
可以将函数作为参数(第一个参数)传递给任何“my:apply()”,my:apply()会将其应用于第二个参数。
使用同样的原则,实现了XSLT1.0和XSLT2.0中的高阶函数(HOF) -- 。
在即将发布的中,函数首次成为 (XDM)中的第一类对象。
发布于 2011-12-03 05:47:27
这是设计好的。xsl:call-template为defined as follows
<!-- Category: instruction -->
<xsl:call-template
name = qname>
<!-- Content: xsl:with-param* -->
</xsl:call-template>name属性必须是qualified name,而不是XPath表达式。
资料来源:
https://stackoverflow.com/questions/8362919
复制相似问题