xsl-list
[Top] [All Lists]

Re: [xsl] how to test previous node name

2007-02-11 14:36:10
Andrew Welch wrote:
On 2/11/07, xslt. new <xslt(_dot_)new(_at_)gmail(_dot_)com> wrote:
Hi all:

I have an XML input:

<test1>
<item></item>
<text></text>
<item></item>
</test1>

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


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

cheers
andrew

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--


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"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>

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

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

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

</xsl:stylesheet>

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

Cheers.

--
Kamal Bhatt


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--