[xsl] Sorting resulttree to multiple levels

Subject: [xsl] Sorting resulttree to multiple levels
From: Jarkko.Moilanen@xxxxxx
Date: Thu, 15 May 2003 12:34:31 +0300
Hi there!

We have managed to get some xml data from a broken software. I am puzzled with
a prob. I am having the simplified xml source as:

<knowledge-object id="id39">
	<metadata>
		<title>MitÀ nyt pitÀisi tehdÀ</title>
	<creator>Sari</creator>
<extra-meta>						<creation-date>2003/01/30</creation-date>
<meta base="FLE3" description="metatype">				
<unstructured-source>Note</unstructured-source>
</meta>
<meta base="FLE3" description="parent">					
<unstructured-source>38</unstructured-source>
</meta>
<meta base="FLE3" description="type">				
<unstructured-source>konteksti</unstructured-source>
</meta>
</extra-meta>
</metadata>
				
</knowledge-object>
<knowledge-object id="id40">
<metadata>
<title>Arvopohjan yleiset osa-alueet</title>
<creator>JukkaS</creator>
<extra-meta>
						<creation-date>2003/01/30</creation-date>
<meta base="FLE3" description="metatype">				
<unstructured-source>Note</unstructured-source>
</meta>
<meta base="FLE3" description="parent">					
<unstructured-source>39</unstructured-source>
</meta>
<meta base="FLE3" description="type">					
<unstructured-source>haaste</unstructured-source>
</meta>
</extra-meta>
</metadata>				
</knowledge-object>

<knowledge-object id="id42">
<metadata>
<title>Hahtuvan sijainti</title>
<creator>Sari</creator>
<extra-meta>
						<creation-date>2003/01/30</creation-date>
<meta base="FLE3" description="metatype">				
<unstructured-source>Note</unstructured-source>
</meta>
<meta base="FLE3" description="parent">					
<unstructured-source>40</unstructured-source>
</meta>
<meta base="FLE3" description="type">					
<unstructured-source>info</unstructured-source>
</meta>
</extra-meta>
</metadata>
</knowledge-object>
			
<knowledge-object id="id43">
<metadata>
<title>Luonnosta ja jatkuvuudesta</title>
<creator>Eerikki</creator>
<extra-meta>
						<creation-date>2003/01/31</creation-date>
<meta base="FLE3" description="metatype">				
<unstructured-source>Note</unstructured-source>
</meta>
<meta base="FLE3" description="parent">					
<unstructured-source>42</unstructured-source>
</meta>
<meta base="FLE3" description="type">					
<unstructured-source>haaste</unstructured-source>
</meta>
</extra-meta>
</metadata>
</knowledge-object>
			
<knowledge-object id="id44">
<metadata>
<title>YrittÀjyys arvopohjan paikalliseksi teemaksi?</title>
<creator>JukkaS</creator>
<extra-meta>
						<creation-date>2003/02/01</creation-date>
<meta base="FLE3" description="metatype">				
<unstructured-source>Note</unstructured-source>
</meta>
<meta base="FLE3" description="parent">					
<unstructured-source>43</unstructured-source>
</meta>
<meta base="FLE3" description="type">					
<unstructured-source>idea</unstructured-source>
</meta>
</extra-meta>
</metadata>
</knowledge-object>
			
<knowledge-object id="id47">
<metadata>
<title>YrittÀjyys kunniaan!</title>
<creator>Anna</creator>
<extra-meta>					<creation-date>2003/02/03</creation-date>
<meta base="FLE3" description="metatype">				
<unstructured-source>Note</unstructured-source>
</meta>
<meta base="FLE3" description="parent">				
<unstructured-source>42</unstructured-source>
</meta>
<meta base="FLE3" description="type">					
<unstructured-source>arvio</unstructured-source>
</meta>
</extra-meta>
</metadata>
</knowledge-object>
			
<knowledge-object id="id50">
<metadata>
<title>yrittÀjyys ja arvopohja</title>
<creator>Pieta</creator>
<extra-meta>
						<creation-date>2003/02/03</creation-date>
<meta base="FLE3" description="metatype">				
<unstructured-source>Note</unstructured-source>
</meta>
<meta base="FLE3" description="parent">					
<unstructured-source>44</unstructured-source>
</meta>
<meta base="FLE3" description="type">					
<unstructured-source>arvio</unstructured-source>
</meta>
</extra-meta>
</metadata>
</knowledge-object>
</root>

What I need is to sort the resulttree. This seems to be somekind of grouping
problem. The structure of xml is supposed to describe a discussion tree.
Should I try some key solution or what?

So the result is supposed to be something like:

id41 (from element <knowledge-object id="41"> )
  47 (<unstructured-source>47</unstructured-source>
  48
   49
    50
   51
  52

id42
  23
   24
    25
   26
  27

Sorry about this messy question. 

I have managed to sort the resulttree for one level by using this template:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
<xsl:template match="/">
	<html>

	<body>
	<xsl:for-each select="//environment">
	<xsl:for-each select="//knowledge-object">
	<xsl:param name="parentID" select="substring-after(@id,'d')"/>

	
	 <xsl:for-each
select="following-sibling::*[metadata/extra-meta/meta[2]/unstructured-source=$parentID]">

	 <h1><xsl:value-of select="metadata/title"/> :object-id:<xsl:value-of
select="@id"/>: source: 
	                       <xsl:value-of
select="metadata/extra-meta/meta[2]/unstructured-source"/></h1>
	 <p><xsl:value-of select="source/p"/></p> 
	</xsl:for-each>
	</xsl:for-each>
	</xsl:for-each> 
		
		
	</body>
	</html>
</xsl:template>
</xsl:stylesheet>


Cheers, 
Jarkko

***************************************************
* Jarkko Moilanen                                 *
* Project Researcher, ITCM (www.itcm.org)         *
* Profound XML technology Expert                  *
* University of Tampere                           *
* Hypermedia Laboratory                           *
***************************************************

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


Current Thread