使用 XSLT 将 OpenOffice/Libreoffic .fodg 文件转换为 ,graphml 时出现问题

Problems converting a OpenOffice/Libreoffic .fodg-file to ,graphml using XSLT

我是 XSLT 的新手,正在尝试将 Libre-/Openoffice 绘图转换为 .graphml 文件以导入到 yEd。 为了进行转换,我开始使用 Notepad++/XML 工具以及 XML Xopy 编辑器。但我一直坚持让元素识别出它们的命名空间。所以我不确定这是否是 XML-Tools 的问题,我不再相信 XML Copy Editor 会出现同样的问题。 问题是,如何从 XSL 文件中寻址 XML 文件中具有名称空间的元素。 一个简单的绘图有以下代码:

<?xml version="1.0" encoding="UTF-8"?>

<office:document 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:presentation="urn:oasis:names:tc:opendocument:xmlns:presentation: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:config="urn:oasis:names:tc:opendocument:xmlns:config: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" xmlns:smil="urn:oasis:names:tc:opendocument:xmlns:smil-compatible:1.0" xmlns:anim="urn:oasis:names:tc:opendocument:xmlns:animation:1.0" xmlns:rpt="http://openoffice.org/2005/report" xmlns:of="urn:oasis:names:tc:opendocument:xmlns:of:1.2" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:grddl="http://www.w3.org/2003/g/data-view#" xmlns:officeooo="http://openoffice.org/2009/office" xmlns:tableooo="http://openoffice.org/2009/table" xmlns:drawooo="http://openoffice.org/2010/draw" xmlns:calcext="urn:org:documentfoundation:names:experimental:calc:xmlns:calcext:1.0" xmlns:loext="urn:org:documentfoundation:names:experimental:office:xmlns:loext:1.0" xmlns:field="urn:openoffice:names:experimental:ooo-ms-interop:xmlns:field:1.0" xmlns:formx="urn:openoffice:names:experimental:ooxml-odf-interop:xmlns:form:1.0" xmlns:css3t="http://www.w3.org/TR/css3-text/" office:version="1.2" office:mimetype="application/vnd.oasis.opendocument.graphics"
>
<!-- 
      In here was still a bunch of  styles and other stuff, which is not necessary for the issue
      -->

 <office:body>
  <office:drawing>
   <draw:page draw:name="page1" draw:style-name="dp2" draw:master-page-name="Standard">
    <draw:custom-shape draw:style-name="gr1" draw:text-style-name="P1" xml:id="id1" draw:id="id1" draw:layer="layout" svg:width="4.7cm" svg:height="2.8cm" svg:x="5.2cm" svg:y="5.2cm">
     <text:p text:style-name="P1">Test Node 1</text:p>
     <draw:enhanced-geometry svg:viewBox="0 0 21600 21600" draw:type="rectangle" draw:enhanced-path="M 0 0 L 21600 0 21600 21600 0 21600 0 0 Z N"/>
    </draw:custom-shape>
    <draw:custom-shape draw:style-name="gr1" draw:text-style-name="P1" xml:id="id2" draw:id="id2" draw:layer="layout" svg:width="4.7cm" svg:height="2.8cm" svg:x="8.8cm" svg:y="10.1cm">
     <text:p text:style-name="P1">Tes Node 2</text:p>
     <draw:enhanced-geometry svg:viewBox="0 0 21600 21600" draw:type="rectangle" draw:enhanced-path="M 0 0 L 21600 0 21600 21600 0 21600 0 0 Z N"/>
    </draw:custom-shape>
    <draw:connector draw:style-name="gr2" draw:text-style-name="P2" draw:layer="layout" draw:type="curve" svg:x1="7.55cm" svg:y1="8cm" svg:x2="11.15cm" svg:y2="10.1cm" draw:start-shape="id1" draw:end-shape="id2" svg:d="M7550 8000c0 1575 3600 525 3600 2100" svg:viewBox="0 0 3601 2101">
     <text:p text:style-name="P1">Test Connector</text:p>
    </draw:connector>
   </draw:page>
  </office:drawing>
 </office:body>
</office:document>

xsl 应该如何提取

 draw:custom-shape

 draw:connector

无论我尝试什么,我都没有得到任何数据returned。

命名空间可能有问题吗?

以下最小化测试 return,错误是找不到样式表。

 <?xml version="1.0" encoding="UTF-8"?>
 <xsl:stylesheet version="1.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
 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:presentation="urn:oasis:names:tc:opendocument:xmlns:presentation: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:config="urn:oasis:names:tc:opendocument:xmlns:config: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" 
 xmlns:smil="urn:oasis:names:tc:opendocument:xmlns:smil-compatible:1.0" 
 xmlns:anim="urn:oasis:names:tc:opendocument:xmlns:animation:1.0" 
 xmlns:rpt="http://openoffice.org/2005/report"
 xmlns:of="urn:oasis:names:tc:opendocument:xmlns:of:1.2" 
 xmlns:xhtml="http://www.w3.org/1999/xhtml" 
 xmlns:grddl="http://www.w3.org/2003/g/data-view#" 
 xmlns:officeooo="http://openoffice.org/2009/office" 
 xmlns:tableooo="http://openoffice.org/2009/table" 
 xmlns:drawooo="http://openoffice.org/2010/draw" 
 xmlns:calcext="urn:org:documentfoundation:names:experimental:calc:xmlns:calcext:1.0" 
 xmlns:loext="urn:org:documentfoundation:names:experimental:office:xmlns:loext:1.0" 
 xmlns:field="urn:openoffice:names:experimental:ooo-ms-interop:xmlns:field:1.0"
  xmlns:formx="urn:openoffice:names:experimental:ooxml-odf-interop:xmlns:form:1.0" 
  xmlns:css3t="http://www.w3.org/TR/css3-text/"  >
    <xsl:template match="/" >
         <xsl:for-each  select="draw:custom-shape">
       Do whatever needed to be done
         </xsl:for-each>
      </xsl:template>
 </xsl:stylesheet>

有什么建议吗?

只需将 <xsl:for-each select="draw:custom-shape"> 更改为 <xsl:for-each select="//draw:custom-shape">

<xsl:template match="/" >中,当前节点是根节点,draw:custom-shape不是office:document的直接子节点。