0

I think it might be a silly question, but I read the documentation but it still not working for me. I have this graphxml (generated my mvn):

<?xml version="1.0" encoding="UTF-8"?> <graphml xmlns="http://graphml.graphdrawing.org/xmlns" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:y="http://www.yworks.com/xml/graphml" xsi:schemaLocation="http://graphml.graphdrawing.org/xmlns http://graphml.graphdrawing.org/xmlns/1.0/graphml.xsd">
  <key for="node" id="d0" yfiles.type="nodegraphics"/> 
  <key for="edge" id="d1" yfiles.type="edgegraphics"/> 
<graph id="dependencies" edgedefault="directed">
<node id="966567431"><data key="d0"><y:ShapeNode><y:NodeLabel>myproject.mulesoft.services:utilitymgmt-services:mule:3.0.0-SNAPSHOT</y:NodeLabel></y:ShapeNode></data></node>
<node id="706960270"><data key="d0"><y:ShapeNode><y:NodeLabel>myproject.mulesoft.context:custom-runtime-context:jar:1.0.0-SNAPSHOT:compile</y:NodeLabel></y:ShapeNode></data></node>
<edge source="966567431" target="706960270"><data key="d1"><y:PolyLineEdge><y:EdgeLabel>compile</y:EdgeLabel></y:PolyLineEdge></data></edge>
<node id="1985178707"><data key="d0"><y:ShapeNode><y:NodeLabel>myproject.mulesoft.library:common-error-library:jar:2.0.0-SNAPSHOT:compile</y:NodeLabel></y:ShapeNode></data></node>
<node id="953191605"><data key="d0"><y:ShapeNode><y:NodeLabel>myproject.mulesoft.notification:utility-common-domains:jar:3.0.0-SNAPSHOT:compile</y:NodeLabel></y:ShapeNode></data></node>
<edge source="1985178707" target="953191605"><data key="d1"><y:PolyLineEdge><y:EdgeLabel>compile</y:EdgeLabel></y:PolyLineEdge></data></edge>
<edge source="966567431" target="1985178707"><data key="d1"><y:PolyLineEdge><y:EdgeLabel>compile</y:EdgeLabel></y:PolyLineEdge></data></edge>
</graph></graphml>

And all I'm trying to do at this point is to generate a HTML that shows a table with the dependencies like:

Dependencies

myproject.mulesoft.services:utilitymgmt-services:mule:3.0.0-SNAPSHOT myproject.mulesoft.context:custom-runtime-context:jar:1.0.0-SNAPSHOT:compile

compile

myproject.mulesoft.library:common-error-library:jar:2.0.0-SNAPSHOT:compile myproject.mulesoft.notification:utility-common-domains:jar:3.0.0-SNAPSHOT:compile

compile

compile

So this is the xsl I have:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
  <html>
  <body>
    <h2>Dependency</h2>
    <table border="1">
      <tr bgcolor="#9acd32">
        <th>Items</th>
      </tr>
 <xsl:for-each select="*">       
<tr>

        <td><xsl:value-of select="/"/></td>

      </tr>
</xsl:for-each>
    </table>
  </body>
  </html>
</xsl:template>
</xsl:stylesheet>

And I was expecting to have each item of the list into a separate TR TD. But instead it's all into the same TR TD.

    Items
    com.quadreal.mulesoft.services:qr-identitymgmt-services:mule:3.0.0-SNAPSHOT com.quadreal.mulesoft.context:quadreal-runtime-context:jar:1.0.0-SNAPSHOT:compile compile com.quadreal.mulesoft.library:qr-common-error-library:jar:2.0.0-SNAPSHOT:compile com.quadreal.mulesoft.notification:quadreal-utility-common-domains:jar:3.0.0-SNAPSHOT:compile compile compile

Also even if I remove the for-each tag and keep only the

It still displaying the whole thing instead displaying only the first element. Also tried to add a template for graph and for-each the elemtns, but then I don't even get the html. I get only the whole text for the dependencies. Am I missing something or there is something with the graphml that is not properly generated?

I'm adding here the expected HTML code:

<html>
  <body>
    <h2>Dependency</h2>
    <table border="1">
      <tr bgcolor="#9acd32">
        <th>Items</th>
      </tr>
      <tr>
        <td>myproject.mulesoft.services:utilitymgmt-services:mule:3.0.0-SNAPSHOT
        </td>
      </tr>
      <tr>
        <td>myproject.mulesoft.context:custom-runtime-context:jar:1.0.0-SNAPSHOT:compile
       </td>
      </tr>
      <tr>
        <td>compile</td>
      </tr>
      <tr>
        <td>myproject.mulesoft.library:common-error-library:jar:2.0.0-SNAPSHOT:compile 
        </td>
      </tr>
<tr>
        <td>myproject.mulesoft.notification:utility-common-domains:jar:3.0.0-SNAPSHOT:compile
        </td>
      </tr>
      <tr>
        <td>compile</td>
      </tr>
      <tr>
        <td>compile</td>
      </tr>
</table>
  </body>
  </html>
Igor
  • 1,397
  • 3
  • 24
  • 56
  • Still getting the same result... Thanks :) – Igor May 19 '17 at 16:16
  • It's possible to copy and paste it from here into the "Try it yourself" on w3schools web site if it helps someone to help me out.https://www.w3schools.com/xml/xsl_value_of.asp – Igor May 19 '17 at 16:19
  • When you say "dependancies", you you mean `node`s, `edge`s, both? More to come later? If both, do you want them ordered as they are, or grouped together? – AntonH May 19 '17 at 16:19
  • yeah, it's what I have into the node/data/y:ShapeNode/y:NodeLabel and what I have into edge/data/y:PolyLineEdge/y:EdgeLabel. I need them on the order they appear on the graphml. – Igor May 19 '17 at 16:20
  • It's not clear what you mean by "dependencies". Please show the **exact** output you expect to get, and show it **as code**. – michael.hor257k May 19 '17 at 16:29
  • @michael.hor257k I updated the question adding the expected HTML code. Thanks. – Igor May 19 '17 at 16:38

1 Answers1

0

You are getting only one table row, because you do:

<xsl:for-each select="*">

from the context of the / root node, established by:

<xsl:template match="/">

The / root node has only one child, and that is the graphml root element.

Perhaps you wanted to do:

<xsl:for-each select="*/*/*"> 

to create a row for every node and/or edge?


Note also that:

<xsl:value-of select="/"/>

makes no sense. It will return the entire text of the entire document. If you'll change it to:

<xsl:value-of select="."/>

you will get the expected result - at least in the given example.

michael.hor257k
  • 113,275
  • 6
  • 33
  • 51
  • 1
    Thanks. I'm getting a better view now. Based on what I read I thought when I put the / I would have the root node as the "parent" then I would be iterating one by one. Modifying it to */*/* and modifying the value-of to I'm not getting 7 tables with the correct information. I wanted all of them in one table only. if I try to put the html body and table tags outside the template, I don't get anything on the screen. – Igor May 19 '17 at 16:43
  • I am afraid I don't follow. If you make the two changes suggested in my answer (and *only* those two changes) you will get the expected result. My own preference would be to select the nodes explicitly by their names, but that's another story. – michael.hor257k May 19 '17 at 16:48
  • It's almost correct, but the for each should be only to generate new TR and TD tags. Instead, it's generating the whole thing. Including this:

    Dependency

    . About using the nodes explicity, I totally agree with you. The only problem is that I wasn't being able to get any of them.
    Items
    – Igor May 19 '17 at 16:50
  • Sorry. I got it wrong here. It's working properly. Thank you so much! – Igor May 19 '17 at 16:54
  • "*I wasn't being able to get any of them.*" See if this helps: http://stackoverflow.com/questions/34758492/xslt-transform-doesnt-work-until-i-remove-root-node/34762628#34762628 – michael.hor257k May 19 '17 at 16:57