RE: [xsl] Hierearchy navigation in XSL

Subject: RE: [xsl] Hierearchy navigation in XSL
From: "Yates, Danny (ANTS)" <danny.yates@xxxxxxxxxx>
Date: Mon, 14 Oct 2002 11:04:26 +0100
Hi Scott,

XML is great for representing hierarchical data structures,
so why use strings to do the same job? If possible, I suggest
you change the input document format to be something like:

  <namespace name="System">
    <class name="Object"/>
    <class name="Array"/>
    <namespace name="Collections">
      <class name="ArrayList"/>
      <class name="Comparer"/>
      <namespace name="Overkill">
        <class name="Grimey"/>
    <namespace name="Runtime">
      <namespace name="Serialization">
         <class name="Formatter"/>
      <namespace name="Remoting">
         <class name="ObjectHandle"/>
  <namespace name="Other">
    <namespace name="SubAPI">
      <class name="Garbage"/>

This will make you problem considerably easier to solve.



Danny Yates
Technical Architect
Abbey National Treasury Services
E-mail: Danny.Yates@xxxxxxxxxx
Phone: +44 20 7612 4017
Fax: +44 20 7612 4342

-----Original Message-----
From: Scott Bronson [mailto:bronson@xxxxxxxxxxx]
Sent: 14 October 2002 10:36
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: [xsl] Hierearchy navigation in XSL

Hello.  I've solved most of this problem, but the last tiny bit has me
stumped.  I'm hoping someone can tell me how to fix this.

Here's some input:

  <class name="Object"       namespace="System"/>
  <class name="Array"        namespace="System"/>
  <class name="ArrayList"    namespace="System.Collections"/>
  <class name="Comparer"     namespace="System.Collections"/>
  <class name="Grimey"       namespace="System.Collections.Overkill"/>
  <class name="Formatter"    namespace="System.Runtime.Serialization"/>
  <class name="ObjectHandle" namespace="System.Runtime.Remoting"/>
  <class name="Garbage"      namespace="Other.SubAPI"/>

My script accepts a parameter that tells where it is in the hierarchy. 
It then outputs all immediate child nodes at that level in the

Some examples: if we're at "System", the script should output
"Collections" and "Runtime".  If we're at "System.Collections", it
should output "Overkill".  If we're at "", it should output "System" and
"Other".  If at "Other", output "SubAPI".  Seems a fairly easy problem,

Here's my script right now:

<xsl:stylesheet xmlns:xsl="";
<xsl:output method="text"/>
<xsl:param name="ns"/>
<xsl:key name='uniq' match='class' use='@namespace'/>

<xsl:template match="/masterdoc">
    <xsl:sort select="@namespace"/>
      <xsl:when test="string-length($ns)=0">
        <xsl:value-of select="@namespace"/>
      <xsl:when test="starts-with(@namespace,concat($ns,'.'))">


Here are some example runs of this script:

xalan -Q -XSL samp1.xsl -IN sample.xml -PARAM ns "'System.Collections'"

xalan -Q -XSL samp1.xsl -IN sample.xml -PARAM ns "'System'"

The last one illustrates the problem.  It should have output only
"Collections" and "Runtime".

I picture the algorithm being something like:
   if(not(already copied string-before("Runtime.Remoting", "."))
      then copy string-before("Runtime.Remoting", ".") to output

I've tried various combinations of preceding, preceding sibling, and
position to try to figure out what I've already output.  I even tried
key() and using IDs to navigate the parent.  All has resulted in

Does anyone have any idea of what I can do?  I'm out of ideas.

Thank you!

    - Scott

 XSL-List info and archive:

This communication (including any attachments) contains confidential information.  If you are not the intended recipient and you have received this communication in error, you should destroy it without copying, disclosing or otherwise using its contents.  Please notify the sender immediately of the error.

Internet communications are not necessarily secure and may be intercepted or changed after they are sent.  Abbey National Treasury Services plc does not accept liability for any loss you may suffer as a result of interception or any liability for such changes.  If you wish to confirm the origin or content of this communication, please contact the sender by using an alternative means of communication.

This communication does not create or modify any contract and, unless otherwise stated, is not intended to be contractually binding.

Abbey National Treasury Services plc. Registered Office:  Abbey National House, 2 Triton Square, Regents Place, London NW1 3AN.  Registered in England under Company Registration Number: 2338548.  Regulated by the Financial Services Authority (FSA).

 XSL-List info and archive:

Current Thread