1

不是 xml 专家我试图从打印机导入日志文件,我需要一个 xlst 文件将其导入文件制作器,但出了点问题

  • 我想要什么结果?
  • _Version 下结果=3.05
  • 在“autoDischargeComposition”下结果=1
  • 在“高度”结果=500.12077
  • 在“宽度”下结果=400.22566
  • 在“scaleFixedRatio”下结果=真
  • 在“高度”下结果=56.20050
  • 在“宽度”下结果=56.10050

所以我只需要名称和结果 xlst 文件现在发生的情况是它只获取

  • _版本 3.05
  • 自动放电组合 1
  • 并跳过其余的!!!!

这是打印机 log.xml 文件:

    <?xml version="1.0" encoding="UTF-8"?> 
    <java version="1.6.0_27" class="java.beans.XMLDecoder"> 
    <object class="rip.properties.XmlEdit"> 
    <void property="_VERSION"> 
    <string>3.05</string> 
    </void> 
    <void property="autoDischargeComposition"> 
    <int>1</int> 
    </void>  
    <void property="scale"> 
    <object class="cmn.math.DimDouble"> 
    <void property="height"> 
    <double>500.12077</double> 
    </void> 
    <void property="width"> 
    <double>400.22566</double> 
    </void> 
    </object> 
    </void> 
   <void property="scaleFixedRatio"> 
   <boolean>true</boolean> 
  </void> 
  <void property="scaleRatio"> 
  <object class="cmn.math.DimDouble"> 
  <void property="height"> 
  <double>56.20050</double> 
  </void> 
  <void property="width"> 
  <double>56.10050</double> 
  </void> 
 </object> 
 </void> 
 </object> 
</java> 

这是 xlst 文件

    <?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" version="1.0" encoding="utf-8" indent="yes"/>

    <xsl:template match="/">

    <FMPXMLRESULT xmlns="http://www.filemaker.com/fmpxmlresult">
    <ERRORCODE>0</ERRORCODE>
    <PRODUCT BUILD="" NAME="" VERSION=""/>
    <DATABASE DATEFORMAT="" LAYOUT="" NAME="" RECORDS="" TIMEFORMAT=""/>

    <METADATA>
    <FIELD NAME="_VERSION" TYPE="NUMBER" EMPTYOK="YES" MAXREPEAT=""/>
    <FIELD NAME="autoDischargeComposition" TYPE="NUMBER" EMPTYOK="YES" MAXREPEAT=""/>

    <FIELD NAME="height" TYPE="NUMBER" EMPTYOK="YES" MAXREPEAT=""/>
    <FIELD NAME="width" TYPE="NUMBER" EMPTYOK="YES" MAXREPEAT=""/>

    <FIELD NAME="scaleRatio" TYPE="NUMBER" EMPTYOK="YES" MAXREPEAT=""/>
    <FIELD NAME="height" TYPE="NUMBER" EMPTYOK="YES" MAXREPEAT=""/>
    <FIELD NAME="width" TYPE="NUMBER" EMPTYOK="YES" MAXREPEAT=""/>

    </METADATA>

    <RESULTSET FOUND="">

    <xsl:for-each select="java/object">
    <ROW MODID="" RECORDID="">
    <COL><DATA><xsl:value-of select="void[@property='_VERSION']/string"/></DATA></COL>
    <COL><DATA><xsl:value-of select="void[@property='autoDischargeComposition']/int"/></DATA></COL>

    <COL><DATA><xsl:value-of select="void[@property='height']/string"/></DATA></COL>
    <COL><DATA><xsl:value-of select="void[@property='width']/string"/></DATA></COL>

    <COL><DATA><xsl:value-of select="void[@property='scaleRatio']/string"/></DATA></COL>
    <COL><DATA><xsl:value-of select="void[@property='height']/string"/></DATA></COL>
    <COL><DATA><xsl:value-of select="void[@property='width']/string"/></DATA></COL> 

    </ROW>

    </xsl:for-each>

    </RESULTSET>
    </FMPXMLRESULT>

    </xsl:template>
    </xsl:stylesheet>
  • 任何帮助将不胜感激谢谢

西宁

4

1 回答 1

0

问题是对于您的“高度”和“宽度”属性,它们嵌套在void内的其他对象元素中

<void property="scaleRatio">
   <object class="cmn.math.DimDouble">
      <void property="height">

但是,您只是<xsl:value-of select="void[@property='height']/string"/>为了获取值,这只会在当前对象元素中查找void元素。我认为您可能应该做这样的事情来应对双重嵌套的空白。

<xsl:value-of 
   select="void[@property='scale']/object/void[@property='height']/double"/>

您遇到的唯一其他问题是您正在为您的 'scaleRatio' 元素寻找一个字符串值。我认为您可能需要在这里使用“scaleFixedRatio”。

尝试以下 XSLT

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
   <xsl:output method="xml" version="1.0" encoding="utf-8" indent="yes"/>
   <xsl:template match="/">
      <FMPXMLRESULT xmlns="http://www.filemaker.com/fmpxmlresult">
         <ERRORCODE>0</ERRORCODE>
         <PRODUCT BUILD="" NAME="" VERSION=""/>
         <DATABASE DATEFORMAT="" LAYOUT="" NAME="" RECORDS="" TIMEFORMAT=""/>
         <METADATA>
            <FIELD NAME="_VERSION" TYPE="NUMBER" EMPTYOK="YES" MAXREPEAT=""/>
            <FIELD NAME="autoDischargeComposition" TYPE="NUMBER" EMPTYOK="YES" MAXREPEAT=""/>
            <FIELD NAME="height" TYPE="NUMBER" EMPTYOK="YES" MAXREPEAT=""/>
            <FIELD NAME="width" TYPE="NUMBER" EMPTYOK="YES" MAXREPEAT=""/>
            <FIELD NAME="scaleRatio" TYPE="NUMBER" EMPTYOK="YES" MAXREPEAT=""/>
            <FIELD NAME="height" TYPE="NUMBER" EMPTYOK="YES" MAXREPEAT=""/>
            <FIELD NAME="width" TYPE="NUMBER" EMPTYOK="YES" MAXREPEAT=""/>
         </METADATA>
         <RESULTSET FOUND="">
            <xsl:for-each select="java/object">
               <ROW MODID="" RECORDID="">
                  <COL>
                     <DATA>
                        <xsl:value-of select="void[@property='_VERSION']/string"/>
                     </DATA>
                  </COL>
                  <COL>
                     <DATA>
                        <xsl:value-of select="void[@property='autoDischargeComposition']/int"/>
                     </DATA>
                  </COL>
                  <COL>
                     <DATA>
                        <xsl:value-of select="void[@property='scale']/object/void[@property='height']/double"/>
                     </DATA>
                  </COL>
                  <COL>
                     <DATA>
                        <xsl:value-of select="void[@property='scale']/object/void[@property='width']/double"/>
                     </DATA>
                  </COL>
                  <COL>
                     <DATA>
                        <xsl:value-of select="void[@property='scaleFixedRatio']/boolean"/>
                     </DATA>
                  </COL>
                  <COL>
                     <DATA>
                        <xsl:value-of select="void[@property='scaleRatio']/object/void[@property='height']/double"/>
                     </DATA>
                  </COL>
                  <COL>
                     <DATA>
                        <xsl:value-of select="void[@property='scaleRatio']/object/void[@property='width']/double"/>
                     </DATA>
                  </COL>
               </ROW>
            </xsl:for-each>
         </RESULTSET>
      </FMPXMLRESULT>
   </xsl:template>
</xsl:stylesheet>

当应用于您的 XML 时,将输出以下内容

<FMPXMLRESULT xmlns="http://www.filemaker.com/fmpxmlresult">
   <ERRORCODE>0</ERRORCODE>
   <PRODUCT BUILD="" NAME="" VERSION=""/>
   <DATABASE DATEFORMAT="" LAYOUT="" NAME="" RECORDS="" TIMEFORMAT=""/>
   <METADATA>
      <FIELD NAME="_VERSION" TYPE="NUMBER" EMPTYOK="YES" MAXREPEAT=""/>
      <FIELD NAME="autoDischargeComposition" TYPE="NUMBER" EMPTYOK="YES" MAXREPEAT=""/>
      <FIELD NAME="height" TYPE="NUMBER" EMPTYOK="YES" MAXREPEAT=""/>
      <FIELD NAME="width" TYPE="NUMBER" EMPTYOK="YES" MAXREPEAT=""/>
      <FIELD NAME="scaleRatio" TYPE="NUMBER" EMPTYOK="YES" MAXREPEAT=""/>
      <FIELD NAME="height" TYPE="NUMBER" EMPTYOK="YES" MAXREPEAT=""/>
      <FIELD NAME="width" TYPE="NUMBER" EMPTYOK="YES" MAXREPEAT=""/>
   </METADATA>
   <RESULTSET FOUND="">
      <ROW MODID="" RECORDID="">
         <COL>
            <DATA>3.05</DATA>
         </COL>
         <COL>
            <DATA>1</DATA>
         </COL>
         <COL>
            <DATA>500.12077</DATA>
         </COL>
         <COL>
            <DATA>400.22566</DATA>
         </COL>
         <COL>
            <DATA>true</DATA>
         </COL>
         <COL>
            <DATA>56.20050</DATA>
         </COL>
         <COL>
            <DATA>56.10050</DATA>
         </COL>
      </ROW>
   </RESULTSET>
</FMPXMLRESULT>
于 2012-11-16T16:42:21.907 回答