xsl-list
[Top] [All Lists]

Re: Re: Network diagram - node set intersection

2004-02-23 13:37:17

<cknell(_at_)onebox(_dot_)com> wrote in message
news:B0022507446(_at_)vljcms11(_dot_)ucmretail(_dot_)internal(_dot_)callsciences(_dot_)com(_dot_)(_dot_)(_dot_)
Thank you for your helpful and speedy reply. I understood two of the three
variables you defined right away, but this puzzled me for a while.

<xsl:variable name="sibling-cnt" select="count($other-predecessor-nodes[.
=$this-predecessor-nodes])" />

Is the select expression saying, "Count all the nodes in
$other-predecessor-nodes where ..., no, I'm still puzzled. Can you please
put this expression in English so I can get a handle on it?

Count all nodes from $other-predecessor-nodes that have a value, equal to
one of the values of $this-predecessor-nodes


As to your remark on the topic of graphML, are you comparing it favorably
to my ASCII art representation of the graph that got mangled at the top of
the post or to the XML sample I showed?

Of course I cannot compare flies to elephants. Your source xml did not
express very well the graph -- the terminology is strange and imprecise, the
format is also ambiguous (A could have been specified to have two successors
instead of one)

The XML was developed strictly as a represenation of the problem. The
original dialect is one I am developing to represent project management data
and is far more involved than the stand-in I posted. The production of this
network diagram is but one relatively minor use for the XML. In order to use
graphML I would have to transform the relevant portions of my project
management language document to graphML and then transform that to SVG. What
is the benefit in my situation of doing that conversion?

The benefit will express itself when any graph problems have to be solved.
Expressing a graph in a convenient and standard way facilitates
understanding and solving the problem. Not to speak that there may be
already tools (to be honest, I don't know of any...) operating on the
standard format.

Like most self-taught programmers, I am weak in the area of computer
science. I have a basic idea of nodes and edges, but I wonder if a jump into
graphML would put me in over my head. Could I get a handle on graphML
without a sound foundation in the fundamentals of computer science?


I cannot say this. In graphML one has a very simple representation of a
graph, like this:

<!DOCTYPE graphml PUBLIC "-GraphML DTD"
  "graphml.dtd" >


<graphml>
  <desc>This is an optional description of the whole document</desc>

  <key id="name"/>

  <graph edgedefault="directed">
    <desc>This is an optional description of the graph</desc>

    <node id="v0">
      <data key="name">S0</data>
    </node>
    <node id="v1">
      <data key="name">S1</data>
    </node>
    <node id="v2">
      <data key="name">S2</data>
    </node>
    <node id="v3">
      <data key="name">S3</data>
    </node>
    <edge id="e0" source="v0" target="v0">
      <data key="name">Start</data>
    </edge>
    <edge id="e1" source="v0" target="v1">
      <data key="name">Clear</data>
    </edge>
    <edge id="e2" source="v1" target="v2">
      <data key="name">SelectMode1</data>
    </edge>
    <edge id="e3" source="v1" target="v3">
      <data key="name">SelectMode2</data>
    </edge>
    <edge id="e4" source="v2" target="v3">
      <data key="name">EnterType1Data</data>
    </edge>
    <edge id="e5" source="v3" target="v2">
      <data key="name">Clear</data>
    </edge>
    <edge id="e6" source="v3" target="v0">
      <data key="name">Stop</data>
    </edge>
  </graph>
</graphml>

The graphML DTD is available at:

http://graphml.graphdrawing.org/dtds/1.0rc/graphml.dtd


Cheers,

Dimitre Novatchev,
FXSL developer,

http://fxsl.sourceforge.net/ -- the home of FXSL
Resume: http://fxsl.sf.net/DNovatchev/Resume/Res.html

-- 
Charles Knell
cknell(_at_)onebox(_dot_)com - email


The reason is you're mixing node-identity with value-identity. The XPath
expression for intersection of two node-sets selects the *identical* nodes
from the two node-sets. In your case you want to find all nodes with the
same *value*.

Here's a transformation, which produces what you want:

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
  <xsl:output method="xml" indent="yes" encoding="UTF-8" />

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

  <xsl:template match="network">
    <xsl:apply-templates />
  </xsl:template>

  <xsl:template match="node">
    <xsl:variable name="this-node-id" select="node-id" />
    <xsl:variable name="this-predecessor-nodes"
         select="/*/node[node-id = current()/node-id]/predecessor-id" />
    <xsl:variable name="other-predecessor-nodes"
         select="/*/node[node-id != $this-node-id]/predecessor-id" />
    <xsl:variable name="sibling-cnt"
    select="count($other-predecessor-nodes
                    [. =$this-predecessor-nodes]
                  )" />

    This node id = <xsl:value-of select="$this-node-id" />
    Sibling count = <xsl:value-of select="$sibling-cnt" />
  </xsl:template>

</xsl:stylesheet>

When this transformation is applied on your source.xml:

<network>
  <node>
    <node-id>A</node-id>
    <predecessor-id></predecessor-id>
    <successor-id>B</successor-id>
  </node>
  <node>
    <node-id>B</node-id>
    <predecessor-id>A</predecessor-id>
    <successor-id>D</successor-id>
  </node>
  <node>
    <node-id>C</node-id>
    <predecessor-id>A</predecessor-id>
    <successor-id>D</successor-id>
  </node>
  <node>
    <node-id>D</node-id>
    <predecessor-id>B</predecessor-id>
    <predecessor-id>C</predecessor-id>
    <successor-id></successor-id>
  </node>
</network>

the wanted result is produced:

    This node id = A
    Sibling count = 0


    This node id = B
    Sibling count = 1


    This node id = C
    Sibling count = 1


    This node id = D
    Sibling count = 0

One final remark: the chosen representation of the graph is not good at
all.
 I'd recommend a better one, e.g. the standard for graph representation -- 
graphML.


Hope this helped.

Cheers,

Dimitre Novatchev ,
FXSL developer,

http://fxsl.sourceforge.net/ -- the home of FXSL
Resume: http://fxsl.sf.net/DNovatchev/Resume/Res.html




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




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






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