RE: [xsl] Yet Another Flat File to Hierarchy question..

Subject: RE: [xsl] Yet Another Flat File to Hierarchy question..
From: "McNally, David" <David.McNally@xxxxxxxxxx>
Date: Fri, 14 Jun 2002 13:56:24 -0400
For some reason I can't get current() to work in key definitions - or at
least that seems to be what the problem is.  Using the suggested key below,
I tried this xslt:


<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
	<xsl:output method="xml" version="1.0" encoding="UTF-8"
indent="yes"/>
<xsl:key name="get-next-level" match="p"
use="generate-id(preceding-sibling::p[@style &lt; current()/@style][1])"/>

<xsl:template match="doc">
	<doc>
		<xsl:apply-templates select="p[@style=1]"/>
	</doc>
</xsl:template>

<xsl:template match="p">
	<xsl:variable name="thisid" select="generate-id(.)"/>
	<p style="{@style}">
		<xsl:apply-templates/>
		<xsl:apply-templates select="key('get-next-level',
$thisid)"/>
	</p>
</xsl:template>
</xsl:stylesheet>

on this xml:

<doc>
	<p style="1">Top Level Heading</p>
	<p style="2">Sub Heading 1</p>
	<p style="3">Sub heading 2</p>
	<p style="3">Sub Heading 3</p>
	<p style="4">Sub Heading 4</p>
	<p style="1">Another Heading</p>
</doc>

and, using saxon 6.4.4, got this output:

<?xml version="1.0" encoding="UTF-8"?>
<doc>
   <p style="1">Top Level Heading</p>
   <p style="1">Another Heading</p>
</doc>

I.e. the key wasn't selecting anything.  With some experimentation it seems
that the key isn't getting set, or is set to '' for all the p elements, and
some simpler key definitions make it seem that it is the current() that is
the culprit.  I get the same results with MSXML.

Is there something I am missing?  Have I made some elementary mistake?  Does
it work for everyone else?

Thanks,
David.
--
David McNally            Moody's Investors Service
Software Engineer        99 Church St, NY NY 10007 
David.McNally@xxxxxxxxxx            (212) 553-7475 

> -----Original Message-----
> From: Paul Bunkham [mailto:paulb@xxxxxxxxxxxxxxxxxxx]
> Sent: Friday, June 14, 2002 3:53 AM
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: RE: [xsl] Yet Another Flat File to Hierarchy question..
> 
> 
> Thank you wendell, I'd been working on something similar, but it would
> appear the the use of current() was the key to success (no 
> pun intended
> :) ).
> 
> Just for the record, the working line of code is:
> 
> <xsl:key name="get-next-level" match="p"
> use="generate-id(preceding-sibling::p[@style &lt; 
> current()/@style][1])"/>
> 
> Thanks again,
> 
> Paul.
> 


---------------------------------------

The information contained in this e-mail message, and any attachment thereto, is confidential and may not be disclosed without our express permission.  If you are not the intended recipient or an employee or agent responsible for delivering this message to the intended recipient, you are hereby notified that you have received this message in error and that any review, dissemination, distribution or copying of this message, or any attachment thereto, in whole or in part, is strictly prohibited.  If you have received this message in error, please immediately notify us by telephone, fax or e-mail and delete the message and all of its attachments.  Thank you.

Every effort is made to keep our network free from viruses.  You should, however, review this e-mail message, as well as any attachment thereto, for viruses.  We take no responsibility and have no liability for any computer virus which may be transferred via this e-mail message.


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


Current Thread