无法从XRTreeFrag投射到XNodeSet [英] Unable to cast from XRTreeFrag into XNodeSet
问题描述
我有以下测试代码...我试图将节点集作为参数传递.几个小时后,我终于能够将其传递到模板中.
I have the following test code... I am trying to pass a node-set as a param. After many hours, i finally was able to pass it to my template.
我如何将节点集传递给模板:
How I pass my node-set to the template:
<xsl:call-template name="listing">
<xsl:with-param name="customData">
<xsl:apply-templates select="exslt:node-set($data)"/>
</xsl:with-param>
</xsl:call-template>
我的模板如何接收它:
<xsl:template name="listing">
<xsl:param name="customData" select="/.."/>
<xsl:variable name="data">
<xsl:choose>
<xsl:when test="not($customData)">
<xsl:value-of select="/data"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$customData"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<textarea><xsl:copy-of select="$data"></xsl:copy-of></textarea>
</xsl:call-template>
如果我用一根衬板设置参数,那么它不会抱怨...例如:
If I set the parameters with a one liner, then it would not complain... example:
<xsl:variable name="data" select="$customData"/>
但是,一旦我尝试将其设置为这样,它就会崩溃:
But as soon as I try to set it like this, it breaks:
<xsl:variable name="data">
<xsl:value-of select="$customData"/>
</xsl:variable>
获取此错误消息: org.apache.xpath.objects.XRTreeFrag无法转换为org.apache.xpath.objects.XNodeSet
我只能找到另一个可以追溯到2000年的线程,谈论这个类似的问题...我需要使用node-set($ customData)/*之类的东西将其重新节点设置回去,但是我尝试过,这是不行的.
I was only been able to find another thread dated back in 2000, talk about this similar issue... I need to re-nodeset it back using something like node-set($customData)/* but I tried that, and it was a no go.
好的,我可以确认我已成功通过模板中的节点集.但是我仍然无法将其复制到我的变量中.它一直说它仍然是RTF.
OK, I can confirm that I successfully passed the node-set inside my template. But I'm still unable to copy it over to my variable... It kept saying that it is still a RTF.
<xsl:template name="listing">
<xsl:param name="customData" as="node-set"/>
<!--<xsl:variable name="data" select="/data"/>-->
<xsl:variable name="data">
<xsl:choose>
<xsl:when test="count($customData) != 0">
<xsl:copy-of select="$customData"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="/data"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<textarea><xsl:value-of select="$customData/record[1]"/></textarea>
<textarea><xsl:value-of select="/data/record[1]"/></textarea>
<textarea><xsl:value-of select="$data/record[1]"/></textarea>
</xsl:template>
上面的测试表明,我可以毫无问题地访问$ customData和原始的/data,它们都显示了记录...但是$ data搞砸了.因此,这意味着从$ customData到$ data的副本无法正常工作...
The above test, shows that I can access $customData and the original /data without any problem, they both show the record... but $data is messed up. So that means the copy from $customData to $data wasn't working...
我尝试了以下方法,但都不起作用:
I tried the following ways, none of them work:
<xsl:copy-of select="$customData"/>
<xsl:value-of select="$customData"/>
<xsl:apply-templates select="exslt:node-set($customData)"/>
<xsl:apply-templates select="exslt:node-set($customData)/data"/>
有什么想法吗??
推荐答案
让它正常工作,而不是使用apply-template,我需要将RTF作为参数传递给模板.那是我让它工作的唯一方法.
Got it working, basically rather than using apply-template, i need to pass the RTF as a parameter to the template. That is the only way I got it to work.
<xsl:with-param name="data" select="exslt:node-set($customData)"/>
使用此方法,我能够修改 XSL级别的数据.这真的很酷,我基本上可以操纵想要的数据,然后重建根目录/,然后将customData传递给模板函数.
Using this method, I was able to MODIFY data in XSL level. This is really cool, I basically manipulate the data I want, then i reconstruct the root /, and then I pass my customData to my template function.
因此,我不是从根目录读取数据,而是读取自己的修改数据(在XSL内部构造).
So rather than reading data off the root, I read my own modified data (constructed inside XSL).
这篇关于无法从XRTreeFrag投射到XNodeSet的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!