微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

xml – 使用XSLT将OpenOffice / Libreoffic .fodg文件转换为graphml的问题

我是XSLT的新手,并试图将Libre- / Openoffice绘图转换为.graphml文件以导入到yEd中.
为了进行转换,我开始使用Notepad / XML Tools和 XML Xopy Editor.但我仍然坚持使用其命名空间来识别元素.所以我不确定这是否是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

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

命名空间可能存在问题吗?

以下最小化的测试返回,并且找不到样式表的错误.

<?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”> to< xsl:for-each select =“// draw:custom-shape”>.

在< xsl:template match =“/”>当前节点是根节点并且绘制:custom-shape不是office的直接子节点:document.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。