This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: XSL-T to map a D(A)G


> Hi all,
>
> The XML consists of a couple of nodes with links inbetween. The links
> are direckted, and one node is the start.

Hi Goetz,

I had a similar problem, to go from a set of single-level
relationships and construct a tree representation.  I think
the recursive algorithm I used in my stylesheet may be useful
for the first part of your problem....

The graphical-SVG part of this is another issue I'll leave
to someone else!

Here was the input (please ignore the structure inherent in the node
names, they are just used to check my results in this example):

<relations>
  <parent name="p">
    <child name="p1"/>
    <child name="p2"/>
  </parent>
  <parent name="p1">
    <child name="p11"/>
    <child name="p12"/>
    <child name="p13"/>
  </parent>
  <parent name="p22">
    <child name="p221"/>
    <child name="p222"/>
  </parent>
  <parent name="p221">
    <child name="p2211"/>
  </parent>
  <parent name="p2">
    <child name="p21"/>
    <child name="p22"/>
  </parent>
</relations>

To this tree style of output:

<node name="p">
  <node name="p1">
    <node name="p11"/>
    <node name="p12"/>
    <node name="p13"/>
  </node>
  <node name="p2">
    <node name="p21"/>
    <node name="p22">
      <node name="p221">
        <node name="p2211"/>
      </node>
      <node name="p222"/>
    </node>
  </node>
</node>


This was my stylesheet:

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

<xsl:output method="xml" indent="yes"/>

<xsl:template match="/">
  <node name="p">
    <xsl:apply-templates select="//parent[@name='p']"/>
  </node>
</xsl:template>

<xsl:template match="parent">
  <xsl:apply-templates select="child"/>
</xsl:template>

<xsl:template match="child">
  <node name="{@name}">
    <xsl:apply-templates select="//parent[./@name=current()/@name]"/>
  </node>
</xsl:template>

</xsl:stylesheet>

Hope this helps,

Nigel

-- 
Nigel Whitaker, nigelw@cs.man.ac.uk, +44 161 275 6270
Dept of Computer Science, University of Manchester, M13 9PL, UK




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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]