0

Guys I want to convert an xml file to GraphML format, so I use the stylesheet below.The stylesheet generates the GraphML file but its schema cannot be validated in a graphml viewer. Can someone point me to what I have wrong in the stylesheet and what I can do to fix it?

Stylesheet:

<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" omit-xml-declaration="no" indent="yes"/>
<xsl:template match="/">
    <graphml xmlns="http://graphml.graphdrawing.org/xmlns" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://graphml.graphdrawing.org/xmlns http://graphml.graphdrawing.org/xmlns/1.0/graphml.xsd">
        <key id="d0" for="node" attr.name="color" attr.type="string">
            <default>yellow</default>
        </key>
        <key id="d1" for="edge" attr.name="weight" attr.type="double">
            <default>1.0</default>
        </key>      
        <key id="d2" for="all" attr.name="name" attr.type="string"/>
        <graph id="G" edgedefault="undirected">
            <xsl:for-each select="network/nodes/node">
                <node id="{position()}">                    
                    <data key="d0"><text>black</text></data>
                    <data key="d2">
                        <xsl:value-of select = "@id"/>
                    </data>
                </node>
            </xsl:for-each>
            <xsl:for-each select="network/links/link">
                <edge id="{position()}" source="{@from}" target="{@to}">
                    <data key="d1">
                       <xsl:value-of select="@length"/>
                    </data>
                    <data key="d2">
                       <xsl:value-of select="@id"/>
                    </data>
                </edge>
            </xsl:for-each>
        </graph>
    </graphml>
</xsl:template>
</xsl:stylesheet>

Output Graphml

<?xml version="1.0" encoding="UTF-8"?><graphml xsi:schemaLocation="http://graphml.graphdrawing.org/xmlns http://graphml.graphdrawing.org/xmlns/1.0/graphml.xsd" xmlns="http://graphml.graphdrawing.org/xmlns" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<key id="d0" for="node" attr.name="color" attr.type="string">
<default>yellow</default>
</key>
<key id="d1" for="edge" attr.name="weight" attr.type="double">
<default>1.0</default>
</key>
<key id="d2" for="all" attr.name="name" attr.type="string"/>
<graph id="G" edgedefault="undirected">
<node id="1">
<data key="d0">
<text>""</text>
</data>
<data key="d2">MyCiTi_1</data>
</node>
<node id="2">
<data key="d0">
<text>""</text>
</data>
<data key="d2">MyCiTi_10</data>
</node>
<node id="3">
<data key="d0">
<text>""</text>
</data>
<data key="d2">MyCiTi_100</data>
</node>
<edge id="1" source="MyCiTi_180" target="MyCiTi_180">
<data key="d1">50.0</data>
<data key="d2">MyCiTi_0</data>
</edge>
<edge id="2" source="MyCiTi_180" target="MyCiTi_58">
<data key="d1">608.4643035761809</data>
<data key="d2">MyCiTi_1</data>
</edge>
<edge id="3" source="MyCiTi_176" target="MyCiTi_192">
<data key="d1">868.3169964115151</data>
<data key="d2">MyCiTi_10</data>
</edge>
</graph>
</graphml>

Input xml:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE network SYSTEM "http://www.matsim.org/files/dtd/network_v2.dtd">
<network>

    <!-- ====================================================================== -->

        <nodes>
            <node id="MyCiTi_1" x="-53196.450154726146" y="-3755010.0058102254" >
            </node>
            <node id="MyCiTi_10" x="-54879.37761845079" y="-3753903.660850382" >
            </node>
            <node id="MyCiTi_100" x="-46659.23389528884" y="-3749500.821686937" >
            </node>
        </nodes>

    <!-- ====================================================================== -->

        <links capperiod="01:00:00" effectivecellsize="7.5" effectivelanewidth="3.75">
            <link id="MyCiTi_0" from="MyCiTi_181" to="MyCiTi_180" length="50.0" freespeed="8.333333333333334" capacity="500.0" >
            </link>
            <link id="MyCiTi_1" from="MyCiTi_180" to="MyCiTi_58" length="608.4643035761809" freespeed="8.333333333333334" capacity="500.0"  >
            </link>
            <link id="MyCiTi_10" from="MyCiTi_176" to="MyCiTi_192" length="868.3169964115151" freespeed="8.333333333333334" capacity="500.0" >
            </link>
        </links>

</network>
Nobi
  • 1,113
  • 4
  • 23
  • 41

1 Answers1

1

If I understand correctly your stylesheet you are mapping node's network as node's graph and network links to graphs edge, and its sound reasonable to me; but your input seems to reprent an unconnected graph.

For example the link with id MyCiTi_0 refers to non existent nodes MyCiTi_181 and MyCiTi_180 and this will would fail as the generated graphml will produce and edge where the source and target node are missing.

gtosto
  • 1,381
  • 1
  • 14
  • 18