views:

24

answers:

2

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.

+1  A: 

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>
derek
I updated my original question.
Kris Van den Bergh
A: 
<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.

Dimitre Novatchev