Subject: RE: [xsl] Re: Network diagram - node set intersection From: cknell@xxxxxxxxxx Date: Mon, 23 Feb 2004 14:50:44 -0500 |
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? 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? 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? 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? -- Charles Knell cknell@xxxxxxxxxx - 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
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] defining namespace / func, Michael Kay | Thread | [xsl] Re: Re: Network diagram - nod, Dimitre Novatchev |
[xsl] Re: Network diagram - node se, Dimitre Novatchev | Date | [xsl] Re: Re: Network diagram - nod, Dimitre Novatchev |
Month |