snaggy Posted November 13, 2006 Share Posted November 13, 2006 here my structure<structure> <menu id="main"> <item/> <item/> <item> <menu id="products"> <item/> <item/> </menu> </item> </menu><menu id="second"> <item/> <item> <menu id="buddies"> <item/> </menu> </item> </menu></structure>or something like that...anyway, I want to select through xPath the element menu with specified id (let's say buddies) and all the ancestors menu items, obtaining an array of menus items (composed of items).i tried something like that but it doesn't work:ancestor-or-self:://menu[@id=products]//ancestor-or-self::menu[@id=products]ancestor-or-self::menu//menu[@id=products]what should I do?bye and thanks you all Link to comment Share on other sites More sharing options...
boen_robot Posted November 13, 2006 Share Posted November 13, 2006 XPath axes are only for use in relative paths as far as I'm aware of.Try something with no axes://menu[@id=products]|//menu[@id=products]/node() Link to comment Share on other sites More sharing options...
aalbetski Posted November 14, 2006 Share Posted November 14, 2006 using XSLT , I came up with this <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:output method="html"/> <xsl:template match="//menu[@id='buddies']"> <xsl:for-each select="ancestor-or-self::*[name()='menu']"> <xsl:value-of select="name()"/><br/> </xsl:for-each> </xsl:template> </xsl:stylesheet> using XMLDOM (msxml parser) and Javascript var oNode = xmlSource.selectSingleNode("//menu[@id='buddies']")var oNodes = oNode.selectNodes("ancestor-or-self::*[name()='menu']") Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now