2

我正处于构建 xslt 文档以将 xml 数据导入自由办公电子表格的早期阶段。xml 数据表示 xgmml 格式的图(带有节点和边)。在这个阶段,我只是(?)尝试选择图中的所有节点,提取“标签”属性,并将每个标签放在电子表格中单行的单元格中。

我能够在 libre-office 中安装 .xslt 并打开 .xgmml 文件。

我可以使用 .xslt 从 .xgmml 中提取一些数据并将其添加到电子表格中

但是,由于某种原因,我无法选择节点并提取标签。

有人可以指出我的(无疑)愚蠢的错误吗?

参考....

我正在处理的 .xgmml .xslt 和 .odt 文档如下:

XGMML------------------------------------------------------

<?xml version="1.0" encoding="UTF-8"?>
<graph directed="1" label="Graph:-1" xmlns="http://www.cs.rpi.edu/XGMML/" xmlns:cy="http://www.cytoscape.org/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#/" xmlns:xlink="http://www.w3.org/1999/xlink/"
xmlns:dc="http://purl.org/dc/elements/1.1/">
    <node id="204g-1" label="204g-1" start="441940">
        <att name="RTC" type="real" value="12.45 " start="443028"/>
        <att name="LTD" type="real" value="1.53 " start="443495"/>
        <att name="LTD" type="real" value="1.63 " start="721167"/>
        <att name="LOD" type="real" value="1.23 " start="721200"/>
        <att name="LOD" type="real" value="1.32 " start="104941642"/>
        <att name="RTC" type="real" value="7.31 " start="106070988"/>
        <att name="LTD" type="real" value="1.76 " start="106071018"/>
        <att name="LTD" type="real" value="1.81 " start="107270843"/>
        <att name="LOD" type="real" value="1.20 " start="107270868"/>
    </node>
    <edge source="204g-1" target="202g-1" label="0e0" start="443681">
        <att name="ITB" type="integer" value="256" start="445896"/>
        <att name="LTD" type="real" value="1.84 " start="445934"/>
        <att name="ITB" type="integer" value="256" start="721217"/>
        <att name="LTD" type="real" value="1.60 " start="721250"/>
        <att name="ITB" type="integer" value="256" start="1047946"/>
        <att name="LTD" type="real" value="1.59 " start="1048117"/>
        <att name="ITB" type="integer" value="256" start="1611675"/>
        <att name="LTD" type="real" value="1.57 " start="1611810"/>
    </edge>
    <node id="202g-1" label="202g-1" start="443660"/>
    <edge source="204g-1" target="84g-1" label="1e1" start="445960" end="9443711">
        <att name="ITB" type="integer" value="148" start="445968"/>
        <att name="LTD" type="real" value="1.98 " start="721301"/>
        <att name="LTD" type="real" value="2.35 " start="1612024"/>
        <att name="LTD" type="real" value="1.99 " start="4159942"/>
        <att name="LTD" type="real" value="1.91 " start="6158290"/>
        <att name="ITB" type="integer" value="3" start="7201361"/>
        <att name="LTD" type="real" value="2.67 " start="8339315"/>
    </edge>
    <node id="84g-1" label="84g-1" start="445959" end="9443711"/>
    <edge source="204g-1" target="27g-1" label="2e2" start="446016" end="876899">
        <att name="ITB" type="integer" value="148" start="446021"/>
        <att name="LTD" type="real" value="1.91 " start="446043"/>
        <att name="ITB" type="integer" value="163" start="721316"/>
        <att name="LTD" type="real" value="1.76 " start="721348"/>
    </edge>
    <node id="27g-1" label="27g-1" start="446015"/>
    <edge source="204g-1" target="17g-1" label="3e3" start="446066" end="2926490">
        <att name="ITB" type="integer" value="148" start="446072"/>
        <att name="LTD" type="real" value="1.71 " start="721396"/>
        <att name="ITB" type="integer" value="168" start="1612329"/>
        <att name="ITB" type="integer" value="218" start="2344316"/>
        <att name="LTD" type="real" value="2.00 " start="2344594"/>
    </edge>
</graph>

XSLT------------------------------------------------ -------------

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/"> 

<office:document-content 
    xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" 
    xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" 
    xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" 
    xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" 
    xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" 
    xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" 
    xmlns:xlink="http://www.w3.org/1999/xlink" 
    xmlns:dc="http://purl.org/dc/elements/1.1/" 
    xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0" 
    xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0" 
    xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" 
    xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0" 
    xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0" 
    xmlns:math="http://www.w3.org/1998/Math/MathML" 
    xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0" xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0" 
    xmlns:ooo="http://openoffice.org/2004/office" 
    xmlns:ooow="http://openoffice.org/2004/writer" 
    xmlns:oooc="http://openoffice.org/2004/calc" 
    xmlns:dom="http://www.w3.org/2001/xml-events" 
    xmlns:xforms="http://www.w3.org/2002/xforms" 
    xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" office:version="1.0">

   <office:body>
    <office:spreadsheet>
     <table:table table:name="nodes">

      <!-- Insert column labels,  -->
      <table:table-row>
       <xsl:for-each select="graph/node">
        <table:table-cell>
         <text:p><xsl:value-of select="@label"/></text:p>
        </table:table-cell>
       </xsl:for-each>
      </table:table-row>    

      <table:table-row>
       <table:table-cell>
        <text:p>the column labels are missing above</text:p>
       </table:table-cell>
      </table:table-row>    

      <table:table-row>
       <table:table-cell>
        <text:p>but this works</text:p>
       </table:table-cell>
      </table:table-row>    

      <table:table-row>
       <xsl:for-each select="//@label">
        <table:table-cell>
         <text:p><xsl:value-of select="."/></text:p>
        </table:table-cell>
       </xsl:for-each>
      </table:table-row>    

      <table:table-row>
       <table:table-cell>
        <text:p>not very useful unfortunately .....</text:p>
       </table:table-cell>
      </table:table-row>    

     </table:table>
    </office:spreadsheet>
   </office:body>
  </office:document-content>
</xsl:template>
</xsl:stylesheet>

ODT-------------------------------------- -----------------

    A       B       C       D       E       F
1   204g1   202g-1  84g-1
2
3
4

1 回答 1

2

Because your graph element has xmlns="http://www.cs.rpi.edu/XGMML/", all the unprefixed elements in your source XML are in this namespace, but in XPath expressions, an unprefixed name matches elements that are not in a namespace. Therefore you need to bind the http://www.cs.rpi.edu/XGMML/ namespace URI to a prefix in your stylesheet and use that prefix in the XPaths:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:g="http://www.cs.rpi.edu/XGMML/" exclude-result-prefixes="g">

  <xsl:template match="/">
    <!-- ... --> 
    <xsl:for-each select="g:graph/g:node">
     <table:table-cell>
      <text:p><xsl:value-of select="@label"/></text:p>
     </table:table-cell>
    </xsl:for-each>
    <!-- ... --> 
  </xsl:template>
</xsl:stylesheet>
于 2013-02-10T13:43:50.817 回答