xsl-list
[Top] [All Lists]

Re: [xsl] Getting the first preceding node

2008-10-17 09:07:08
lac wrote:
Hi List!

I need a little help in a XPath expression.

This is a test xml

<?xml version="1.0" encoding="UTF-8"?>
<element type="cat">CAT 1</element>
<element>PROD 1</element>
<element>PROD 2</element>
<element>PROD 3</element>
<element>PROD 4</element>

<element type="cat">CAT 2</element>
<element>PROD 5</element>
<element>PROD 6</element>
<element>PROD 7</element>
<element>PROD 8</element>

How can I get the first preceding element which has an attribute by
name type, and value is cat?

For example:

In PROD 1 is the result CAT 1
In PROD 5 is the result CAT 2


Sorry for my bad language, and thanks for the help.

Lac

I think you want this XPath:

preceding-sibling::element[(_at_)type='cat'][1]


        Ronan

-- 
Ronan Klyne
Business Collaborator Developer
Tel: +44 01189 028518
ronan(_dot_)klyne(_at_)groupbc(_dot_)com
www.groupbc.com

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

<Prev in Thread] Current Thread [Next in Thread>