Welcome to yEd Q&A!
Here you can ask questions and receive answers from other members of the community and yEd developers. And you can tell us your most wanted feature requests.

Categories

Open an XML file with data inside, not only elements

0 votes
Hi everyone,

I'm trying to open a xml file with yEd in the aim of visualising data.

It works but the graph consist in visualising XML's elements, not the data contained in.

For exemple:

<c id="de-130" level="item">
<did>
<unittitle label="Intitulé de l'unité documentaire">Eytan, Moshi. <emph render="italic">Convexité dans les ensembles ordonnés</emph>. Rap. /26/août 1969/M. Eytan</unittitle>
<unitdate label="Date de l'unité documentaire" normal="1969">1969</unitdate>
</did>
<controlaccess>
<head>Descripteurs</head>
<genreform label="Typologie documentaire">rapport</genreform>
<subject label="Mot matière libre">ensemble convexe</subject>
<subject label="Mot matière libre">calcul</subject>
<subject label="Mot matière libre" source="liste-discipline">mathématiques</subject>
<persname label="Personne">Eytan, Moshi</persname>
<genreform source="liste-niveau">document</genreform>
</controlaccess>
</c>

Generated nodes are: "Controlaccess", "Genreform", "Subject" .... instead of: "rapport", "calcul" or "Eytan, Moshi", which are data I want to see.

However, the entire structure is perfect: all the edges are correct.

Can anyone help me?

Best regards,

Julien, French archivist
in Help by

1 Answer

0 votes

You need to write an XSLT stylesheet that transforms your XML into GraphML according to your requirements. You can use this stylesheet as a starting point:

<xsl:stylesheet
 version="1.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
 xmlns:y="http://www.yworks.com/xml/graphml"
 xmlns="http://graphml.graphdrawing.org/xmlns">
  <xsl:output method="xml" indent="yes"/>
  <xsl:template match="/">
    <graphml
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://graphml.graphdrawing.org/xmlns http://www.yworks.com/xml/schema/graphml/1.1/ygraphml.xsd">
      <key id="d0" for="node" yfiles.type="nodegraphics"/>
      <key id="d1" for="edge" yfiles.type="edgegraphics"/>
      <graph id="G" edgedefault="directed">
        <xsl:apply-templates select="//*" mode="create-nodes"/>
        <xsl:apply-templates select="/*//*" mode="create-edges"/>
      </graph>
    </graphml>
  </xsl:template>
  <xsl:template match="//*" mode="create-nodes">
    <xsl:element name="node">
      <xsl:attribute name="id">
        <xsl:value-of select="generate-id()"/>
      </xsl:attribute>
      <data key="d0">
        <y:ShapeNode>
          <y:Fill color="#CCCCCC"/>
          <y:NodeLabel>&lt;html&gt;&lt;div
            style="font-size:120%;color:blue;"&gt;
            <xsl:value-of
                select="name()"/>
            &lt;/div&gt;
            <xsl:for-each select="@*">
              <xsl:value-of select="name()"/>
              =&quot;
              <xsl:value-of select="."/>
              &quot;&lt;br&gt;
            </xsl:for-each>
          </y:NodeLabel>
        </y:ShapeNode>
      </data>
    </xsl:element>
  </xsl:template>
  <xsl:template match="//*" mode="create-edges">
    <xsl:element name="edge">
      <xsl:attribute name="id">
        <xsl:value-of select="generate-id()"/>
      </xsl:attribute>
      <xsl:attribute name="source">
        <xsl:value-of select="generate-id(parent::node())"/>
      </xsl:attribute>
      <xsl:attribute name="target">
        <xsl:value-of select="generate-id()"/>
      </xsl:attribute>
    </xsl:element>
  </xsl:template>
</xsl:stylesheet>

 

After importing your data, run "Tools" -> "Fit Node to Label" and "Layout" -> "Tree" -> "Directed".

by [yWorks] (161k points)
Thank you very much.

I tried with your XSLT stylesheet and there are some changes making me think it can provide a solution.
Now I have to learn XSLT!
Legal Disclosure | Privacy Policy
...