[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: What's wrong with my ancestor syntax?

Subject: RE: What's wrong with my ancestor syntax?
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Mon, 26 Mar 2007 23:55:03 +0100
RE:  What's wrong with my ancestor syntax?
Your menuItem element doesn't have an ancestor called pageID so
ancestor-or-self::pageID will select nothing.

I'm not really sure what you want but you seem to need descendants rather
than ancestors.

Michael Kay
http://www.saxonica.com/ 

> -----Original Message-----
> From: Austin, Darrel [mailto:Darrel.Austin@xxxxxxxxxxxxxxxxxx] 
> Sent: 26 March 2007 22:59
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject:  What's wrong with my ancestor syntax?
> 
> I'm trying to use ancestor-or-self.
> 
> Here's a sample of the XML:
> <menuItems>
>  <menuItem>
>       <pageID>938</pageID>
>       <browserTitle>Home Page</browserTitle>
>       <lastUpdate>2006/06/12</lastUpdate>
>       <menuItem>
>          <pageID>998</pageID>
>          <browserTitle>District Administration</browserTitle>
>          <lastUpdate>2006/06/06</lastUpdate>
>       </menuItem>
>  </menuItem>
> <menuItems>
> 
> This is the XML that forms our site menu. I want to create an 
> RSS feed that lists the most recent 10 pages that have been 
> changed under a certain node of the menu.
> 
> So, for this example, I want to pass in the page ID of '938' 
> and return both '938' and any child page underneath it.
> 
> Here's the XSL:
> 
> <xsl:param name="pageID">1</xsl:param>
> 
> <xsl:template match="/">
> 	<xsl:for-each 
> select="*/menuItem[ancestor-or-self::pageID = $pageID]"> 
> 		<xsl:sort select="substring(@lastUpdate,1,4)"
> order="descending" /> <!-- year  -->
> 		<xsl:sort select="substring(@lastUpdate,6,2)"
> order="descending" /> <!-- month -->
> 		<xsl:sort select="substring(@lastUpdate,9,2)"
> order="descending" /> <!-- day   -->
> 		<xsl:call-template name="createItem" />
> 	</xsl:for-each>
> </xsl:template>
> 
> <xsl:template name="createItem">
> 		lastUpdate: <xsl:value-of select="lastUpdate"/>
> 		browserTitle: <xsl:value-of select="browserTitle"/>
> 		pageID: <xsl:value-of select="pageID"/> </xsl:template>
> 
> Originally, I had 'descendant-or-self' by mistake which 
> obviously gave me the exact opposite of what I wanted and 
> returned the specific node and all PARENT pages that matched. 
> So I changed to ancestor-or-self and now it doesn't appear to 
> match anything. I'm not sure why. Is my logic a bit off?
> 
> -Darrel

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.