【问题标题】:Output XML from combined XML's in a XSL从 XSL 中的组合 XML 输出 XML
【发布时间】:2012-11-25 16:11:30
【问题描述】:

我在弄清楚如何从导入两个 XML 并组合数据的 XSL 中输出干净的 XML 时遇到了一些大问题。

我试图找到有关<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/> 的更多信息,我认为这是我的解决方案,但我不知道如何将所有这些信息放入一个可靠的 xml 文件中。当我从服务器脚本调用它时,它看起来不错,但它有一些 HTML 标记和其他我不想要的东西,我想这是因为它仍然是 XSL。

这是我的代码:

<?xml version="1.0" encoding="UTF-8" ?>  
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet">

  <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>

  <xsl:param name="source-producenter" select="'Producers.xml'"/>
  <xsl:param name="source-positioner" select="'positioner.xml'"/>
  <xsl:variable name="producenter" select="document($source-producenter)"/>
  <xsl:variable name="Workbook" select="document($source-positioner)"/>

  <xsl:template match="/">
    <Producers>
      <xsl:for-each select="$producenter//producer">
        <producer>

          <id>
            <xsl:value-of select="id"/>
          </id>

          <name>
            <xsl:value-of select="name"/>
          </name>

          <address><xsl:value-of select="address"/></address>

          <postalcode>
            <xsl:value-of select="postalcode"/>
          </postalcode>

          <city>
            <xsl:value-of select="city"/>
          </city>

          <site>
            <xsl:value-of select="site"/>
          </site>

          <pic>
            <xsl:value-of select="img"/>
          </pic>
          <!--Store id from producent into storeId xsl variable -->
          <xsl:variable name="storedId" select="id"/>
          <!--Using filter to get correct Cells for latitude and longitude and checks if text() in number is equal to our storedId variable-->
          <xsl:variable name="selected"
            select="$Workbook//ss:Cell[@ss:Index='2']/ss:Data[@ss:Type='Number' and text() = $storedId]"/>
          <!--Gets the filtered values-->
          <latitude>
            <xsl:value-of select="$selected//../../ss:Cell[2]/ss:Data"/>
          </latitude>
          <longitude>
            <xsl:value-of select="$selected//../../ss:Cell[3]/ss:Data"/>
          </longitude>
        </producer>
      </xsl:for-each>
    </Producers>
  </xsl:template>
</xsl:stylesheet>

感谢所有答案,提前谢谢!

【问题讨论】:

  • 请编辑问题并提供: 1.确切的两个 XML 文档(请尽可能小)。 2. 将转换应用于这两个 XML 文件时得到的确切结果。 3. 你得到的结果有什么问题。 4. 您想要获得的确切结果(对于这两个指定的 XML 文档)。

标签: xml xslt xml-parsing xslt-1.0


【解决方案1】:

如果您正在转换由 MSExcel 生成的 XML(线索是某些元素的 ss: 前缀),请注意 Excel 使用 @ss:Index 属性的方式。连续的单元格忽略此属性,但要跳过空白的中间单元格,后续单元格有一个@ss:index。重建部分填充的细胞矩阵的几何形状是相当痛苦的。我不太明白这是否与您的挑战有关。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-06
    • 1970-01-01
    • 1970-01-01
    • 2014-12-20
    相关资源
    最近更新 更多