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

RE: xsl:number and including nodes with xsl:key

Subject: RE: xsl:number and including nodes with xsl:key
From: "Michael Kay" <mhk@xxxxxxxxx>
Date: Fri, 29 Aug 2003 09:11:13 +0100
for each xsl not resetting
<xsl:number> gives you a number based on the position of the current
node within the tree that it's part of. It's not affected by the
processing that led you to that node.

If your processing of <insert> elements is fully recursive, then I think
the best solution is the same as recommended to another poster earlier
this week: do two phases, one to create the nodes in the result tree,
the second to number them.

Michael Kay

> -----Original Message-----
> From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx 
> [mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of 
> Denis Haskin
> Sent: 29 August 2003 04:03
> To: XSL-List@xxxxxxxxxxxxxxxxxxxxxx
> Subject:  xsl:number and including nodes with xsl:key
> 
> 
> I sincerely apologize if this is a FAQ; I'm unable to find an 
> answer to 
> this in the archives nor the FAQ (although there are a couple of FAQ 
> entries that are similar to this and imply to me that what I'm doing 
> should work).
> 
> I am using xsl:key and select="key()" to include part of my 
> input tree 
> at another place during processing.  This works fine, but the 
> problem is 
> I'm trying to using xsl:number as well and I can't prevent xsl:number 
> from resetting (apparently) its context while processing the 
> referred-to 
> nodes.  (Apologies if my terminology is not correct; I'm back to XSL 
> after having not used it much in the last year-plus.)
> 
> Here's a *very* simplified example.  Here's my input XML:
> 
> <test>
> <extra myid="extraid"><name>Extra item</name></extra>
> <item>
>  <name>Item one</name>
>  <name>Item two</name>
>  <name>Item three</name>
>  <insert ref="extraid"/>
> </item>
> </test>
> 
> 
> and I'm processing it with this XSL:
> 
> 
> <?xml version="1.0" encoding="UTF-8"?>
> 
> <xsl:stylesheet 
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
> 
> <xsl:key name="testkey" match="extra" use="@myid"/>
> 
> <xsl:template match="insert">
>   <xsl:variable name="d" select="key('testkey',@ref)"/>
>   <xsl:apply-templates select="$d" mode="include"/> </xsl:template>
> 
> <xsl:template match="name">
>   <xsl:number/> - <xsl:value-of select="."/>
> </xsl:template>
> 
> <xsl:template match="extra" mode="include">
>   <xsl:apply-templates/>
> </xsl:template>
> 
> <xsl:template match="extra"/>
> 
> </xsl:stylesheet>
> 
> what I'm getting for output is this:
> 
>   1 - Item one
>   2 - Item two
>   3 - Item three
>   1 - Extra item
> 
> and what I want is:
> 
>   1 - Item one
>   2 - Item two
>   3 - Item three
>   4 - Extra item
> 
> Is this possible?  I've messed a bunch with level, from, 
> count, etc without any luck.  I feel like this should be a 
> no-brainer...
> 
> Much thanks --
> 
> dwh
> 
> 
> 
> 
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
> 


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


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.