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

RE: another hierarchical problem

Subject: RE: another hierarchical problem
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Thu, 28 Jun 2007 13:09:57 +0100
RE:  another hierarchical problem
Best approach to this is XSLT 2.0

<xsl:for-each-group select="*" group-starting-with="skill">
  <skill name="{.}">
    <xsl:copy-of select="subsequence(current-group(), 2)"/>
  </skill>
</xsl:for-each>

Having said that, I haven't worked out why your current code doesn't work.

Michael Kay
http://www.saxonica.com/ 

> -----Original Message-----
> From: Thomas Kielczewski [mailto:thomaskiel@xxxxxxxxx] 
> Sent: 28 June 2007 12:39
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject:  another hierarchical problem
> 
> 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/

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.