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

Reordering a complex hierarchical structure

Subject: Reordering a complex hierarchical structure
From: Ian Wootten <I.M.Wootten@xxxxxxxxxxxxxxxx>
Date: Wed, 30 Aug 2006 16:10:33 +0100
complex hierarchical
I'm attempting to structure a complex xml structure to be represented in
a more meaningful manner. I'm doing this within a xml transformer in Java.

Currently the structure is like this:

<session>
   <service>
         <name>somename</name>
         <id>1</id>
   </service>
   <metric name="somemetric">value1</metric>
   <metric name="anothermetric">value2</metric>
   <metric name="andanothermetric">value3</metric>
</session>
<session>
   <service>
         <name>somename</name>
         <id>1</id>
   </service>
   <metric name="somemetric">value4</metric>
   <metric name="anothermetric">value5</metric>
   <metric name="andanothermetric">value6</metric>
</session>
<session>
   <service>
         <name>anothername</name>
         <id>2</id>
   </service>
   <metric name="somemetric">value7</metric>
   <metric name="anothermetric">value8</metric>
   <metric name="andanothermetric">value9</metric>
</session>
<session>
   <service>
         <name>anothername</name>
         <id>2</id>
   </service>
   <metric name="somemetric">value10</metric>
   <metric name="anothermetric">value11</metric>
   <metric name="andanothermetric">value12</metric>
</session>

I'd like it to be structured as follows

service  ----> id1 ---->  somemetric ----> value1
                          -----> somemetric ----> value4
                           ---->  anothermetric ----> value2
                          -----> anothermetric ----> value5
                           -----> andanothermetric ----> value3
                          -----> andanothermetric ----> value6
            ------> id 2 ---->  somemetric----> value7
                          -----> somemetric ----> value10
                           ---->  anothermetric ----> value8
                          -----> anothermetric ----> value11
                           -----> andanothermetric ----> value9
                          -----> andanothermetric ----> value12

I currently use an xsl stylesheet like the following, which basically
collects all the metrics from the document and orders them by the name
they have.

<xsl:key name = "x" match="metric" use="@name"/>

   <xsl:template match="/">
       <interactions>
           <xsl:apply-templates select="//session"/>
       </interactions>
   </xsl:template>

   <xsl:template match="session">
       <service name="{service/name}">
           <request><xsl:value-of select="service/id" /></request>
                   <xsl:apply-templates select="metric[generate-id(.) =
generate-id(key('x', @name)[1])]" />
       </service>
     </xsl:template>

   <xsl:template match="metric">
       <metric name="{@name}">
       <xsl:for-each select="key('x', @name)">
       <xsl:for-each select="value">
           <value>
           <xsl:value-of select="node()" />
             </value>
       </xsl:for-each>

       </xsl:for-each>
            </metric>
   </xsl:template>

I am struggling to determine how I can "divide" this structure up so it
appears by the identifier on each service. Once the structure has been
created in this manner the identifiers for the services which they were
under are lost. Is anyone able to help?

Many thanks,

Ian

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.