Re: [xml] wanted: an xpath expression



Stefan Seefeld writes:
Sorry to reply to my own mail, but thinking about
the problem I'll restate the goal:

Imagine I have a hierarchy of 'item' elements (such
as in a menu):

<item title="foo">
   <item title="bar">
     <item title="bla"/>
   </item>
   <item title="baz">
     <item title="bla"/>
   </item>
</item>

I'd like to identify individual 'items'. I can't just use
the 'title' attribute, as that may be ambiguous. However, using
the whole path (i.e. a concatenation of all the title attributes
of all parent items) in the tree would work.

THe problem is now how to use that in xslt. I'd like to use
such a structure as the menu for a set of pages, each identifying
itself with one such 'menu item path'. When generating the menu in
the navigation bar, I have to know whether 'this page' is inside
the current 'item', so I can display it unfolded or collapsed.

Is there a way to ask a given 'item' node whether it contains
an item with the so constructed 'id' is 'foo.baz.bla' ?

        You can use an xpath expression like

item[ title='foo']/item[ title='bar']

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
                version="1.0">

  <xsl:output method="text"/>

  <xsl:param name="selected-path" select="item[ title='foo']/item[ title='bar']/item[ title='bla']"/>

  <xsl:template match="/">
    <xsl:apply-templates select="$selected-path"/>
  </xsl:template>

  <xsl:template match="item">
    item: <xsl:value-of select="@title"/>
  </xsl:template>

</xsl:stylesheet>

-- 
Raymond Wiker                        Mail:  Raymond Wiker fast no
Senior Software Engineer             Web:   http://www.fast.no/
Fast Search & Transfer ASA           Phone: +47 23 01 11 60
P.O. Box 1677 Vika                   Fax:   +47 35 54 87 99
NO-0120 Oslo, NORWAY                 Mob:   +47 48 01 11 60

Try FAST Search: http://alltheweb.com/




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]