Html 使用XSLT填充垂直列数据

Html 使用XSLT填充垂直列数据,html,xml,xslt,Html,Xml,Xslt,我是XSLT新手,下面是我的XML <Aus> <au> <ele> <auid>Au1</auid> <cid>C1</cid> <fn>F1</fn> <sn>S1</sn> <dept>D1</dept> </ele>

我是XSLT新手,下面是我的XML

<Aus>
  <au>
     <ele>
        <auid>Au1</auid>
        <cid>C1</cid>
        <fn>F1</fn>
        <sn>S1</sn>
        <dept>D1</dept>
     </ele>
     
     <ele>
        <auid>Au2</auid>
        <cid>C2</cid>
        <fn>F2</fn>
        <sn>S2</sn>
        <dept>D2</dept>
     </ele>
     
     <ele>
        <auid>Au3</auid>
        <cid>C3</cid>
        <fn>F3</fn>
        <sn>S3</sn>
        <dept>D4</dept>
     </ele>..............
  </au>
</Aus>

但XSLT代码应该很简单,可以通过位置增量标识下一列。请帮帮我

我现在的代码是

<xsl:for-each select="//Aus/au">
<table>
<tr>
<td><xsl:value-of select="ele[1]/auid"/></td><td><xsl:value-of select="ele[2]/auid"/></td><td><xsl:value-of select="ele[3]/auid"/></td>
</tr>
<tr>
<td><xsl:value-of select="ele[1]/cid"/></td><td><xsl:value-of select="ele[2]/cid"/></td><td><xsl:value-of select="ele[3]/cid"/></td>
</tr>
..........
</table>
</xsl:for-each>

..........

我会这样做:

  <xsl:template match="Aus/au">
      <table>
          <tbody>
              <xsl:apply-templates select="ele[1]/*" mode="row"/>
          </tbody>
      </table>
  </xsl:template>
  
  <xsl:template match="ele/*" mode="row">
      <tr>
          <xsl:variable name="pos" select="position()"/>
          <xsl:apply-templates select="../../ele/*[$pos]"/>
      </tr>
  </xsl:template>
  
  <xsl:template match="ele/*">
      <td>
          <xsl:value-of select="."/>
      </td>
  </xsl:template>

你在评论中链接的示例似乎有更复杂的输入数据,因为它似乎有嵌套的元素,也似乎有很多没有数据的元素;然而,模板可适用于以下情况:

  <xsl:template match="authorDetails/authors">
      <table>
          <tbody>
              <xsl:apply-templates 
                select="element[1]/descendant::*[not(*)]" mode="row"/>
          </tbody>
      </table>
  </xsl:template>
  
  <xsl:template match="element//*" mode="row">
      <tr>
          <th>
              <xsl:value-of select="local-name()"/>
          </th>
          <xsl:variable name="pos" select="position()"/>
          <xsl:apply-templates select="ancestor::authors/element/descendant::*[not(*)][$pos]"/>
      </tr>
  </xsl:template>
  
  <xsl:template match="element//*">
      <td>
          <xsl:value-of select="."/>
      </td>
  </xsl:template>


示例:

我会这样做:

  <xsl:template match="Aus/au">
      <table>
          <tbody>
              <xsl:apply-templates select="ele[1]/*" mode="row"/>
          </tbody>
      </table>
  </xsl:template>
  
  <xsl:template match="ele/*" mode="row">
      <tr>
          <xsl:variable name="pos" select="position()"/>
          <xsl:apply-templates select="../../ele/*[$pos]"/>
      </tr>
  </xsl:template>
  
  <xsl:template match="ele/*">
      <td>
          <xsl:value-of select="."/>
      </td>
  </xsl:template>

你在评论中链接的示例似乎有更复杂的输入数据,因为它似乎有嵌套的元素,也似乎有很多没有数据的元素;然而,模板可适用于以下情况:

  <xsl:template match="authorDetails/authors">
      <table>
          <tbody>
              <xsl:apply-templates 
                select="element[1]/descendant::*[not(*)]" mode="row"/>
          </tbody>
      </table>
  </xsl:template>
  
  <xsl:template match="element//*" mode="row">
      <tr>
          <th>
              <xsl:value-of select="local-name()"/>
          </th>
          <xsl:variable name="pos" select="position()"/>
          <xsl:apply-templates select="ancestor::authors/element/descendant::*[not(*)][$pos]"/>
      </tr>
  </xsl:template>
  
  <xsl:template match="element//*">
      <td>
          <xsl:value-of select="."/>
      </td>
  </xsl:template>


示例:

似乎是一项微不足道的任务。你到底在哪里?嗨,迈克尔,谢谢你的问题。现在我在这里更新了我的例外输出和当前代码。它需要手动输入来识别和指定代码中的元素位置。另外,代码中未手动指定的元素输入的“n”个数。我看到您已将预期结果更改为数据透视表。这似乎是一项微不足道的任务。你到底在哪里?嗨,迈克尔,谢谢你的问题。现在我在这里更新了我的例外输出和当前代码。它需要手动输入来识别和指定代码中的元素位置。另外,代码中未手动指定的元素输入的“n”个数。我发现您已将预期结果更改为数据透视表。对于“作者详细信息”引用链接下的标记,在我的原始代码中它不起作用。如果您发布某个示例,您将获得与该示例一起工作的代码。我不知道要在不同的XML中处理哪些元素。要么尝试修改代码,要么用失败的尝试问一个新问题,但要用最少的样本来证明这个特定问题,而不是用无关的数据。wavv great Martin Honnen,我得到了结果。非常感谢你。谢谢stackoverflow.comIt在我的原始代码中不适用于“作者详细信息”下的标记,请参考链接如果您发布了一些示例,您将获得与该示例一起使用的代码。我不知道要在不同的XML中处理哪些元素。要么尝试修改代码,要么用失败的尝试问一个新问题,但要用最少的样本来证明这个特定问题,而不是用无关的数据。wavv great Martin Honnen,我得到了结果。非常感谢你。谢谢stackoverflow.com