0

I'm having a problem to transform my graphml to a HTML using XSLT. The transformation I'm trying to do is pretty simple but I can't understand what I'm doing wrong at this point.

This is my graphml that I want to transform:

<?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="2086673744">
      <data key="d0">
        <y:ShapeNode>
          <y:NodeLabel>com.quadreal.mulesoft.services:qr-identitymgmt-services:mule:3.0.0-SNAPSHOT</y:NodeLabel>
        </y:ShapeNode>
      </data>
    </node>

    <node id="1296670053">
      <data key="d0">
        <y:ShapeNode>
          <y:NodeLabel>com.quadreal.mulesoft.context:quadreal-runtime-context:jar:1.0.0-SNAPSHOT:compile</y:NodeLabel>
        </y:ShapeNode>
      </data>
    </node>

    <edge source="2086673744" target="1296670053">
      <data key="d1">
        <y:PolyLineEdge>
          <y:EdgeLabel>compile</y:EdgeLabel>
        </y:PolyLineEdge>
      </data>
    </edge>

    <node id="826245889">
      <data key="d0">
        <y:ShapeNode>
          <y:NodeLabel>com.quadreal.mulesoft.library:qr-common-error-library:jar:2.0.0-SNAPSHOT:compile</y:NodeLabel>
        </y:ShapeNode>
      </data>
    </node>

    <node id="1556730832">
      <data key="d0">
        <y:ShapeNode>
          <y:NodeLabel>com.quadreal.mulesoft.notification:quadreal-utility-common-domains:jar:3.0.0-SNAPSHOT:compile</y:NodeLabel>
        </y:ShapeNode>
      </data>
    </node>

    <edge source="826245889" target="1556730832">
      <data key="d1">
        <y:PolyLineEdge>
          <y:EdgeLabel>compile</y:EdgeLabel>
        </y:PolyLineEdge>
      </data>
    </edge>

    <edge source="2086673744" target="826245889">
      <data key="d1">
        <y:PolyLineEdge>
          <y:EdgeLabel>compile</y:EdgeLabel>
        </y:PolyLineEdge>
      </data>
    </edge>

  </graph>
</graphml>

This is my XSL that will be used to transform the graphml:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="html" indent="yes"/>

    <xsl:template match="/">
      <html>
        <body>
          <h1>Dependencies:</h1>
          <table border="1" width="300">
            <tr><th>Package Name</th><th>Dependencies</th></tr>
            <xsl:apply-templates select="/graphml/graph/*"/>
          </table>
        </body>
      </html>
    </xsl:template>

    <xsl:template match="node">
      <tr><td><xsl:value-of select="data/ShapeNode/NodeLabel"/></td><td>TBD</td></tr>
    </xsl:template>

</xsl:stylesheet>

And this is the output I'm getting:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><META http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body><div>
<h1>Dependencies:</h1>
<table border="1" width="300"><tr>
<th>Package Name</th>
<th>Dependencies</th>
</tr></table>
</div>
</body></html>

I tried in many different ways to have this one working but they didn't work. Why it's not matching and applying the node template to add the rows properly?

Thank you!

Igor
  • 1,297
  • 3
  • 19
  • 49

1 Answers1

0

It doesn't match because node is in namespace xmlns="http://graphml.graphdrawing.org/xmlns"

Declare the same namespace in your stylesheet (with a non-empty prefix) and use it in the xpath expressions

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:g="http://graphml.graphdrawing.org/xmlns"
    xmlns:y="http://www.yworks.com/xml/graphml">

    ...
    <xsl:apply-templates select="/g:graphml/g:graph/*"/>
    ...
    <xsl:template match="g:node">
        <tr><td><xsl:value-of select="g:data/y:ShapeNode/y:NodeLabel"/></td><td>TBD</td></tr>
    </xsl:template>
    ...
wero
  • 30,527
  • 3
  • 46
  • 72