Filemaker XSL 按名称选择列

发布于 2024-09-05 02:30:59 字数 861 浏览 8 评论 0原文

我希望使用列名称(而不是位置)从 Filemaker 导出。目前,我导出以下按位置导出的 XSL 样式表:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
  xmlns:fm="http://www.filemaker.com/fmpxmlresult" exclude-result-prefixes="fm" >
<xsl:output method="xml" version="1.0" encoding="utf-8" indent="yes"/>
<xsl:template match="/">
  <people>
    <xsl:for-each select="fm:FMPXMLRESULT/fm:RESULTSET/fm:ROW">
      <person>
        <name>
          <xsl:value-of select="fm:COL[01]/fm:DATA"/>
        </name>
        <location>
          <xsl:value-of select="fm:COL[02]/fm:DATA"/>
        </location>
      </person>
    </xsl:for-each> 
  </people>
</xsl:template>
</xsl:stylesheet>

有什么想法吗?谢谢。

I am looking to export from Filemaker using column names (instead of positions). Currently I export the following XSL stylesheet that exports by position with:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
  xmlns:fm="http://www.filemaker.com/fmpxmlresult" exclude-result-prefixes="fm" >
<xsl:output method="xml" version="1.0" encoding="utf-8" indent="yes"/>
<xsl:template match="/">
  <people>
    <xsl:for-each select="fm:FMPXMLRESULT/fm:RESULTSET/fm:ROW">
      <person>
        <name>
          <xsl:value-of select="fm:COL[01]/fm:DATA"/>
        </name>
        <location>
          <xsl:value-of select="fm:COL[02]/fm:DATA"/>
        </location>
      </person>
    </xsl:for-each> 
  </people>
</xsl:template>
</xsl:stylesheet>

Any ideas? Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

于我来说 2024-09-12 02:30:59

如果您只是想让代码更具可读性,那么我建议使用一些简单的方法,例如:

<!-- expected columns -->
<xsl:variable name="NAME" value="1" />
<xsl:variable name="LOCATION" value="2" />
<!-- ... -->
<people>
  <xsl:for-each select="fm:FMPXMLRESULT/fm:RESULTSET/fm:ROW">
    <person>
      <name>
        <xsl:value-of select="fm:COL[$NAME]/fm:DATA"/>
      </name>
      <location>
        <xsl:value-of select="fm:COL[$LOCATION]/fm:DATA"/>
      </location>
    </person>
  </xsl:for-each> 
</people>

顺便说一句,使用 您可以省略 fm: DATA,即使用:

<xsl:value-of select="fm:COL[$LOCATION] />

会返回相同的结果。

如果您需要更复杂的东西,请解释一下。

更新:

通过列名引用列比较困难,但可以使用类似的方法:

<!-- Define a key to get a field and all fields that precede it by the field name -->
<xsl:key name="N" match="/fm:FMPXMLRESULT/fm:METADATA/fm:FIELD" use="@NAME" />
<xsl:key name="N" match="/fm:FMPXMLRESULT/fm:METADATA/fm:FIELD" 
  use="following-sibling::fm:FIELD/@NAME" />
<!-- Then *count* them it in the code like that -->
<people>
  <xsl:for-each select="fm:FMPXMLRESULT/fm:RESULTSET/fm:ROW">
    <person>
      <name>
        <xsl:value-of select="fm:COL[count(key('N', 'name'))]" />
      </name>
      <location>
        <xsl:value-of select="fm:COL[count(key('N', 'location'))]" />
      </location>
    </person>
  </xsl:for-each> 
</people>

不完全优雅,但有效。

If you just want to make the code more readable, then I'd suggest something simple, like:

<!-- expected columns -->
<xsl:variable name="NAME" value="1" />
<xsl:variable name="LOCATION" value="2" />
<!-- ... -->
<people>
  <xsl:for-each select="fm:FMPXMLRESULT/fm:RESULTSET/fm:ROW">
    <person>
      <name>
        <xsl:value-of select="fm:COL[$NAME]/fm:DATA"/>
      </name>
      <location>
        <xsl:value-of select="fm:COL[$LOCATION]/fm:DATA"/>
      </location>
    </person>
  </xsl:for-each> 
</people>

BTW, with <xsl:value-of /> you can omit the fm:DATA, i.e. use:

<xsl:value-of select="fm:COL[$LOCATION] />

It will return the same result.

If you need something more sophisticated, please explain.

Update:

To refer to columns by column names is harder, but possible with something like that:

<!-- Define a key to get a field and all fields that precede it by the field name -->
<xsl:key name="N" match="/fm:FMPXMLRESULT/fm:METADATA/fm:FIELD" use="@NAME" />
<xsl:key name="N" match="/fm:FMPXMLRESULT/fm:METADATA/fm:FIELD" 
  use="following-sibling::fm:FIELD/@NAME" />
<!-- Then *count* them it in the code like that -->
<people>
  <xsl:for-each select="fm:FMPXMLRESULT/fm:RESULTSET/fm:ROW">
    <person>
      <name>
        <xsl:value-of select="fm:COL[count(key('N', 'name'))]" />
      </name>
      <location>
        <xsl:value-of select="fm:COL[count(key('N', 'location'))]" />
      </location>
    </person>
  </xsl:for-each> 
</people>

Not utterly elegant, but works.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文