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

标签 xml xslt notepad++ openoffice.org libreoffice

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

<?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

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

命名空间是否存在问题?

以下最小化测试返回一个错误,即找不到样式表。

 <?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 的直接子代.

关于xml - 使用 XSLT 将 OpenOffice/Libreoffic .fodg 文件转换为 ,graphml 时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30428995/

相关文章:

c# - 使用索引选择 XML 元素

java - 如何在 Android 中的操作栏下方添加阴影?

regex - notepad++ 正则表达式替换匹配文本的内部序列

regex - 使用 Notepad++ 正则表达式在url中用破折号替换下划线

xslt - 如何将 xpath 表达式转换为 xsl key ?

regex - Notepad++ RegEx 搜索/替换 : How to append and prepend a character at start and end of each file line?

php - WSSE - XML SOAP 安全和 key 加密和存储 (EncryptedData/EncryptedKey)

mysql - XML 插入性能到 MYSQL

XSLT 对两个属性的乘积求和

xslt - 客户端XSLT