伙计我想将xml文件转换为GraphML格式,因此我使用下面的样式表。样式表生成GraphML文件,但无法在graphml查看器中验证其架构。有人能指出我在样式表中的错误以及我可以做些什么来解决它?
样式表:
<?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>
输出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>
输入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>
答案 0 :(得分:1)
如果我理解你的样式表,你将节点的网络映射为节点的图形和网络链接到图形边缘,它对我来说是合理的;但是你的输入似乎代表了一个未连接的图形。
例如,带有 MyCiTi_0 的链接指的是不存在的节点 MyCiTi_181 和 MyCiTi_180 ,这将失败,因为生成的{{1将产生和边缘缺少源节点和目标节点。