XSLT:在当前处理方式内使用不同的处理方式

发布于 2024-08-31 00:12:31 字数 1116 浏览 3 评论 0 原文

下面我尝试匹配某些节点。

<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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

一萌ing 2024-09-07 00:12:31

如果“节点”指的是包含匹配中的同一组节点,请尝试:

<xsl:template match="nodes">    
    <element>
        <xsl:apply-templates select="." mode="different" />
    </element>
</xsl:template>

if "nodes" is referring to the same exact set of nodes in the containing match, try:

<xsl:template match="nodes">    
    <element>
        <xsl:apply-templates select="." mode="different" />
    </element>
</xsl:template>
一束光,穿透我孤独的魂 2024-09-07 00:12:31


    

        <某些元素> 
                

选择=“Foundation.Core.Association.connection”
模式=“不同”/>

如你所见,我选择
Foundation.Core.Association.connection。
这当然是错误的,但是我该怎么办
参考这个元素给定
当前元素和位置?

使用

<xsl:apply-templates select=".." mode="different" />

要进行不同处理的元素是当前节点的父节点

当然,很可能这种复杂的处理根本没有必要,如果您能够显示更多的 XML 文档并以更简洁的方式表述问题,这一点将得到证实。

<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" />

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?

Use:

<xsl:apply-templates select=".." mode="different" />

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文