Re: [xsl] how to test previous node name

Subject: Re: [xsl] how to test previous node name
From: Kamal Bhatt <kbhatt@xxxxxxxxx>
Date: Mon, 12 Feb 2007 08:40:33 +1100
Andrew Welch wrote:
On 2/11/07, xslt. new <> wrote:
Hi all:

I have an XML input:


How do I check if the previous node name for <item> is test1 or text?

select="preceding::*[1][self::item1 or self::text]"


OK, Andrew and I have different interpretations of what you said, further complicated by the fact that in your example, test1 is never preceding an item (it is the parent of the item). Here is what I had, based on what you requested then by what I assume you actually want.

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"

<xsl:template match="test1">
<xsl:apply-templates select="item[preceding::*[1][local-name() = 'text']" mode="text"/>
<xsl:apply-templates select="item[preceding::*[1][local-name() = 'test1']" mode="test1"/>

<xsl:template match="item" mode="text">
 ...processing for text...

<xsl:template match="item" mode="test1">
 ...processing for text...


You could use parent::* in a similar way, if that is actually what you want.


Kamal Bhatt

Current Thread