I am trying to pass Items to a node-set while looping through ancerstors, but for some reason I only get the first recorded Item, and it was the last one I was looking for, the closest ancestor to where I am.
The only place where you can use the backwards-selection order of the ancestor:: and ancestor-or-self:: axes, is in a predicate within the same "step" of an XPath selection, e.g.:
<!-- First ancestor that has an id matching one in the deliveryOptions set -->
<xsl:variable name="firstMatch" select="$CurrentCategory/ancestor-or-self::*[id = $deliveryOptionsProxy/Item/@id][1]" />
<!-- Take the value of the duration attribute from the matching Item -->
<xsl:variable name="deliveryTime" select="$deliveryOptions/Item[@id = $firstMatch/id]/@duration" />
Does that make sense? It requires the ids to be unique across delivery options, but I guess they are, right?
Actually, the idea of this approach was that you had ALL possible options in that deliveryOptions variable once and for all - collecting all the options from $holder_24 $holder_72 etc...
Then you'd be able to select without using a for-each ...
What are the ids on those ancestors? Are they not references to a delivery method of some sort?
node-set Items in loops
I am trying to pass Items to a node-set while looping through ancerstors, but for some reason I only get the first recorded Item, and it was the last one I was looking for, the closest ancestor to where I am.
<xsl:variable name="delivery">
<xsl:for-each select="$CurrentCategory/ancestor-or-self::*">
<xsl:if test="id = $holder24/Item">
<Item>2</Item>
</xsl:if>
<xsl:if test="id = $holder48/Item">
</xsl:if>
<xsl:if test="id = $holder72/Item">
<Item>3</Item>
</xsl:if>
</xsl:for-each>
</xsl:variable>
<xsl:variable name="holder_delivery" select="msxsl:node-set($delivery)" />
Hi Nicolai,
The only place where you can use the backwards-selection order of the ancestor:: and ancestor-or-self:: axes, is in a predicate within the same "step" of an XPath selection, e.g.:
or the one referred to as a recursive lookup for the first ancestor with a value in a specific property:
If you only want to look at the first ancestor, you can use the parent:: axis (abbreviated as "..") instead:
/Chriztian
Hey again Chriztian ;)
problem is that I am comparing it against 3 node-sets to se which one is closest and the last value passed if any will be the one I need.
I guess you should be able to stuff all the delivery options into a single set - a la:
And then select like this:
Does that make sense? It requires the ids to be unique across delivery options, but I guess they are, right?
/Chriztian
It makes alot of sense, and yes the id's are unique.
Just tested it and I get a: Prefix 'make' is not defined
Ha - that's just because it isn't - only my code can use that :-)
You can just use msxsl:node-set() as you're used to...
/Chriztian
Was thinking that and it removed the error and it saved. Somehow I ended up with a parse error instead.
this one makes the parse error :
<xsl:variable name="firstMatch" select="$CurrentCategory/ancestor-or-self::*[id = $deliveryOptionsProxy/Item/@id][1]" />
Ah yes - sorry about that, it should be "deliveryOptions" instead...
I get no results and it should have 2 passed from the first for-each.
<xsl:variable name="deliveryOptionsProxy">
<xsl:for-each select="$CurrentCategory/ancestor-or-self::*">
<xsl:if test="id = $holder24/Item">
<Item id="d24" duration="2"/>
</xsl:if>
<xsl:if test="id = $holder48/Item">
</xsl:if>
<xsl:if test="id = $holder72/Item">
<Item id="d72" duration="3"/>
</xsl:if>
</xsl:for-each>
</xsl:variable>
<xsl:variable name="deliveryOptions" select="msxsl:node-set($deliveryOptionsProxy)" />
<xsl:variable name="firstMatch" select="$CurrentCategory/ancestor-or-self::*[id = $deliveryOptions/Item/@id][1]" />
<xsl:variable name="deliveryTime" select="$deliveryOptions/Item[@id = $firstMatch/id]/@duration" />
<xsl:value-of select="$deliveryTime"/>
is it the id from the items that are making the problem as we search for ancestor id = Item id?
Hi Nicolai,
Actually, the idea of this approach was that you had ALL possible options in that deliveryOptions variable once and for all - collecting all the options from $holder_24 $holder_72 etc...
Then you'd be able to select without using a for-each ...
What are the ids on those ancestors? Are they not references to a delivery method of some sort?
/Chriztian
ah so I have to merge the node-sets using id's?
there is no reference to how long time it will take to recieve the delivery, thats why I try to add it by a category and whats below it.
is working on a reply...