xsl-list
[Top] [All Lists]

[xsl] another hierarchical problem

2007-06-28 04:39:04
Hi all,

Given the flat XML:

<root>
   <skill>skill1</skill>
   <procedure>procedure</procedure>
   <note>note</note>
   <supplies>supplies</supplies>
   <cleanup>cleanup</cleanup>
   <skill>skill2</skill>
   ...
</root> 

I would like to structure this. I'm using the
generate-id/preceding-sibling method but unlike the
example I base this on, I would like to call ALL
elements types to be under it hierarchically
(following-sibling::*). However, when I try the
following XSLT, <skill> begins nesting ad infinitum,
eventually maxing out the memory allocated to saxon-j.


Can anyone see anything wrong with this?

<xsl:output method="xml" indent="yes" />
<xsl:strip-space elements="*"/>

<xsl:template match="skill">
    <xsl:element name="{name()}">
       <xsl:attribute name="id" select="text()"/>
    <xsl:apply-templates
select="following-sibling::*[generate-id(preceding-sibling::skill[1])
= generate-id(current())]" />
    </xsl:element>
</xsl:template>
    
<xsl:template match="*">
     <xsl:copy-of select="." />
</xsl:template>

<xsl:template match="root">
    <xsl:apply-templates select="skill" />
</xsl:template>
</xsl:stylesheet>

Perhaps another flat-to-hierarchical method is better
suited? 

What if I need to create multiple levels of nesting?
Could that be done in a single stylesheet? Once I
solve my first problem, I could easily do it in
several passes. I also toyed with the idea of building
a structured "skeleton" of my parent element <skill>
into a template and then populating it. Is that an
accepted technique?


I appreciate any pointers,
Thomas Kiel



       
____________________________________________________________________________________
Choose the right car based on your needs.  Check out Yahoo! Autos new Car 
Finder tool.
http://autos.yahoo.com/carfinder/

--~------------------------------------------------------------------
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>
--~--

<Prev in Thread] Current Thread [Next in Thread>