On 3/26/07, Austin, Darrel
<Darrel(_dot_)Austin(_at_)courts(_dot_)state(_dot_)mn(_dot_)us> wrote:
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?
If I've understood what mean, you just need:
<xsl:template match="/">
<xsl:apply-templates select="//menuItem[pageID = $pageID">
<xsl:sort ......./>
and then change the named template to be a match:
<xsl:template match="menuItem">
Also if your dates are yyyy/mm/dd then you can replace your 3 sorts with:
<xsl:sort select="translate(@lastUpdate, '/', '')" data-type="number"/>
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>
--~--