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

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

Subject: Re: XSL-T to map a D(A)G
From: Nigel Whitaker <nigelw@xxxxxxxxxxxx>
Date: Tue, 2 Oct 2001 17:28:32 +0100 (BST)
xsl child name
> 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@xxxxxxxxxxxx, +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


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.