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

Re: building a hierarchical classification out of flat

Subject: Re: building a hierarchical classification out of flat and redundant data
From: David Carlisle <davidc@xxxxxxxxx>
Date: Mon, 24 Jul 2006 12:03:43 +0100
name of hierarchical building
This is a grouping problem, in XSLT2 I think you just want

<xsl:stylesheet version="2.0"  xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

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

  <xsl:template match="x" name="group">
    <xsl:param name="level" select="1"/>
    <xsl:param name="items" select="document"/>
    <xsl:for-each-group select="$items" group-by="*[name()=concat('tag',$level)]">
      <node id="{current-grouping-key()}" name="{*[name()=concat('tag',$level,'a')]}">
	<xsl:call-template name="group">
	  <xsl:with-param name="level" select="$level+1"/>
	  <xsl:with-param name="items" select="current-group()"/>
	</xsl:call-template>
      </node>
    </xsl:for-each-group>
  </xsl:template>
</xsl:stylesheet>


In XSLT1 you can do the same thing, but just replace for-each-group by
one of the standard XSLT 1 grouping idioms (see faq or Jeni's site)

<x>
<document>
	<tag1>3</tag1>
	<tag1a>Social Sciences</tag1a>
</document>
<document>
	<tag1>3</tag1>
	<tag1a>Social Sciences</tag1a>
	<tag2>32</tag2>
	<tag2a>Politics</tag2a>
</document>
<document>
	<tag1>3</tag1>
	<tag1a>Social Sciences</tag1a>
	<tag2>32</tag2>
	<tag2a>Politics</tag2a>
	<tag3>326</tag3>
	<tag3a>Slavery</tag3a>
</document>
<document>
	<tag1>3</tag1>
	<tag1a>Social Sciences</tag1a>
	<tag2>33</tag2>
	<tag2a>Economics</tag2a>
</document>
</x>


$ saxon8 grp2.xml grp2.xsl

<?xml version="1.0" encoding="UTF-8"?>
<node id="3" name="Social Sciences">
   <node id="32" name="Politics">
      <node id="326" name="Slavery"/>
   </node>
   <node id="33" name="Economics"/>
</node>

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.