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

Re: Reordering a complex hierarchical structure

Subject: Re: Reordering a complex hierarchical structure
From: David Carlisle <davidc@xxxxxxxxx>
Date: Wed, 30 Aug 2006 16:26:52 +0100
Re:  Reordering a complex hierarchical structure
something like this if i understood correctly

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  
  <xsl:output indent="yes"/>
  <xsl:key name="id" match="service" use="id"/>
  
  <xsl:template match="/">
    <xsl:for-each select="/x/session/service[generate-id()=generate-id(key('id',id))]">
      <service>
	<xsl:copy-of select="name|id"/>
	<xsl:for-each select="key('id',id)/../metric">
	  <xsl:sort select="@name"/>
	  <xsl:copy-of select="."/>
	</xsl:for-each>
      </service>
    </xsl:for-each>
    </xsl:template>
</xsl:stylesheet>

$ saxon session.xml session.xsl
<?xml version="1.0" encoding="utf-8"?>
<service>
   <name>somename</name>
   <id>1</id>
   <metric name="andanothermetric">value3</metric>
   <metric name="andanothermetric">value6</metric>
   <metric name="anothermetric">value2</metric>
   <metric name="anothermetric">value5</metric>
   <metric name="somemetric">value1</metric>
   <metric name="somemetric">value4</metric>
</service>
<service>
   <name>anothername</name>
   <id>2</id>
   <metric name="andanothermetric">value9</metric>
   <metric name="andanothermetric">value12</metric>
   <metric name="anothermetric">value8</metric>
   <metric name="anothermetric">value11</metric>
   <metric name="somemetric">value7</metric>
   <metric name="somemetric">value10</metric>
</service>

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-2007 All Rights Reserved.