下面我尝试匹配某些节点。
<xsl:template match="nodes">
<element>
<xsl:apply-templates select="nodes" mode="different" />
</element>
</xsl:template>
现在,对于同一个节点有多种处理方式。我想在当前的处理方式中使用这种不同的处理方式。这就是为什么我在同一选择(即节点)上执行应用模板,但现在模式不同了。
以下是不同模式的外观:
<xsl:template match="nodes" mode="different">
<!-- another way of processing these nodes -->
</xsl:template>
现在,这不起作用。仅处理第一种类型的处理,并且根本不应用 apply-templates
调用。
更具体一点:
<xsl:template match="Foundation.Core.Association.connection">
<xsl:for-each select="Foundation.Core.AssociationEnd">
<someElement>
<xsl:apply-templates select="Foundation.Core.Association.connection" mode="different" />
</someElement>
</xsl:for-each>
</xsl:template>
如您所见,我选择了 Foundation.Core.Association.connection。当然这是错误的,但是在给定当前元素和位置的情况下,我如何引用这个元素呢?鉴于德里克的评论,应该可以了。
我做错了什么,如何使用 XSLT 获得我想要的东西?解决这个问题的另一种方法是什么?
谢谢。
Below I'm trying to match certain nodes.
<xsl:template match="nodes">
<element>
<xsl:apply-templates select="nodes" mode="different" />
</element>
</xsl:template>
Now, there are multiple ways of processing for the same nodes. I want to use this different way of processing within the current way of processing. That's why I perform apply-templates
on the same selection, which is nodes
, however the mode
is different now.
Here's how the different mode could look like:
<xsl:template match="nodes" mode="different">
<!-- another way of processing these nodes -->
</xsl:template>
Now, this does not work. Only the first type of processing is processed and the apply-templates
call is simply not applied.
To be a bit more specific:
<xsl:template match="Foundation.Core.Association.connection">
<xsl:for-each select="Foundation.Core.AssociationEnd">
<someElement>
<xsl:apply-templates select="Foundation.Core.Association.connection" mode="different" />
</someElement>
</xsl:for-each>
</xsl:template>
As you can see, I select Foundation.Core.Association.connection
. Of course this is wrong, but how do I refer to this element given the current element and position? Given Derek his comment, that should do it.
What am I doing wrong, how can I get what I want using XSLT? What could be another approach to solve this problem?
Thanks.
发布评论
评论(2)
如果“节点”指的是包含匹配中的同一组节点,请尝试:
if "nodes" is referring to the same exact set of nodes in the containing match, try:
使用:
要进行不同处理的元素是当前节点的父节点。
当然,很可能这种复杂的处理根本没有必要,如果您能够显示更多的 XML 文档并以更简洁的方式表述问题,这一点将得到证实。
Use:
The element you want to process differently is the parent of the current node.
Of course, most likely this convoluted processing is not necessary at all, which would be confirmed, had you been able to show more of the XML document and to formulate the problem in a more succint way.