transpose/swap x,y axes in html table

后端 未结 1 687
情话喂你
情话喂你 2021-01-14 09:33

I have an html table that needs rotating / axis swaping. It can be done off line. Any one know of a tool I can use to do it?

相关标签:
1条回答
  • 2021-01-14 10:09

    This transformation:

    <xsl:stylesheet version="1.0"
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
     <xsl:output omit-xml-declaration="yes"/>
    
     <xsl:template match="table">
         <xsl:for-each select="tr[1]/td">
          <xsl:variable name="vRowPos" select="position()"/>
          <tr>
           <xsl:for-each select="/table/tr">
            <xsl:variable name="vColPos" select="position()"/>
            <xsl:copy-of select="/table/tr[$vColPos]/td[$vRowPos]"/>
           </xsl:for-each>
          </tr>
         </xsl:for-each>
     </xsl:template>
    </xsl:stylesheet>
    

    when applied on this XML document:

    <table>
     <tr>
      <td>A11</td>
      <td>A12</td>
      <td>A13</td>
      <td>A14</td>
      <td>A15</td>
     </tr>
     <tr>
      <td>A21</td>
      <td>A22</td>
      <td>A23</td>
      <td>A24</td>
      <td>A25</td>
     </tr>
     <tr>
      <td>A31</td>
      <td>A32</td>
      <td>A33</td>
      <td>A34</td>
      <td>A35</td>
     </tr>
    </table>
    

    produces the wanted, correct results:

    <table>
        <tr>
            <td>A11</td>
            <td>A21</td>
            <td>A31</td>
        </tr>
        <tr>
            <td>A12</td>
            <td>A22</td>
            <td>A32</td>
        </tr>
        <tr>
            <td>A13</td>
            <td>A23</td>
            <td>A33</td>
        </tr>
        <tr>
            <td>A14</td>
            <td>A24</td>
            <td>A34</td>
        </tr>
        <tr>
            <td>A15</td>
            <td>A25</td>
            <td>A35</td>
        </tr>
    </table>
    

    Do note: The assumption is that the table has regular structure.

    0 讨论(0)
提交回复
热议问题