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

Re: "not a node item" inside distinct-values

Subject: Re: "not a node item" inside distinct-values
From: "andrew welch" <andrew.j.welch@xxxxxxxxx>
Date: Thu, 8 Jun 2006 15:17:09 +0100
not a node item
On 6/8/06, Rick Roen <Rick@xxxxxxxxxxxxxxxxxx> wrote:
XSLT 2.0
XML Spy

I have the following snippet of xml:

        <item racknum="1" traynum="7" pocketnum="11" itemnum="176"
qty_ship="12">SQUASH BENNINGS GREEN TINT</item>
        <item racknum="1" traynum="7" pocketnum="12" itemnum="177"
qty_ship="42">SQUASH BLACK BEAUTY</item>
        <item racknum="1" traynum="7" pocketnum="13" itemnum="178"
qty_ship="18">SQUASH EARLY PROLIFIC STRAIGHT NECK</item>
        <item racknum="2" traynum="8" pocketnum="1" itemnum="179"
qty_ship="12">SQUASH EARLY SUMMER CROOKNECK</item>
        <item racknum="2" traynum="8" pocketnum="2" itemnum="180"
qty_ship="6">SWISS CHARD FORDHOOK GIANT</item>
        <item racknum="2" traynum="8" pocketnum="3" itemnum="183"
qty_ship="24">TOMATO CELEBRITY HYBRID</item>
        <item racknum="2" traynum="8" pocketnum="4" itemnum="204"
qty_ship="24">TOMATO FLAVOR KING HYBRID</item>
        <item racknum="2" traynum="8" pocketnum="5" itemnum="186"
qty_ship="30">WATERMELON CRIMSON SWEET</item>
        <item racknum="2" traynum="8" pocketnum="6" itemnum="205"
qty_ship="12">WATERMELON SUGAR BABY</item>


I want to get the largest @pocketnum for each @racknum, i.e. racknum = 1 largest pocketnum = 13, racknum = 2 largest pocketnum = 6

My XSLT is like this:

<xsl:for-each select="distinct-values(//item/@racknum)">
        <xsl:variable name="rack-num" select="."/>
        <xsl:variable name="pocket-num" select="//item[./@racknum =
$rack-num and position() = last()]"/>
        <p>Rack: <xsl:value-of select="$rack-num"/> max pocket:
<xsl:value-of select="$pocket-num"/></p>
</xsl:for-each>

I get an error "Error in XPath 2.0 expression Not a node item"

Oustide of the <xsl:for-each... I can use:

<xsl:value-of select="//item[./@racknum = 2 and position() =
last()]/@pocketnum"/>

and get the results I expect, i.e. 6.

This must have something to do with the context within the "for-each", but I
can't figure out how to get the information.

It does, and this I think will become a FAQ for XSLT 2.0


This context within the for-each is an item in a sequence, not a node,
so all the usual axis steps aren't available.  Apparently they did
consider having a context node and a context item - where any node
traversal would be against the node, otherwise the context would be
the item, but deemed that too confusing.  What this means is that you
need to save the context node in a variable before the context becomes
an item (within the distinct) and use that variable as the base for
node-based work:

<xsl:variable name="contextNode" select="."/>
<xsl:for-each select="distinct-values(...)">
 <xsl:value-of select="$contextNode/...........

cheers
andrew

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.