GraphML 样式表
Stylesheet for GraphML
伙计们,我想将 xml 文件转换为 GraphML 格式,所以我使用样式表 below.The 样式表生成 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>
输出图表
<?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>
如果我对你的样式表的理解正确的话,你正在将节点的网络映射为节点的图形,并将网络 links 映射到图形的边缘,这对我来说听起来很合理;但您的输入似乎代表了一个未连接的图形。
例如id为MyCiTi_0的link指的是不存在的节点MyCiTi_181和 MyCiTi_180 这将失败,因为生成的 graphml
将在源节点和目标节点缺失的地方生成边缘。
伙计们,我想将 xml 文件转换为 GraphML 格式,所以我使用样式表 below.The 样式表生成 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>
输出图表
<?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>
如果我对你的样式表的理解正确的话,你正在将节点的网络映射为节点的图形,并将网络 links 映射到图形的边缘,这对我来说听起来很合理;但您的输入似乎代表了一个未连接的图形。
例如id为MyCiTi_0的link指的是不存在的节点MyCiTi_181和 MyCiTi_180 这将失败,因为生成的 graphml
将在源节点和目标节点缺失的地方生成边缘。