使用 xslt 将 xml 数据分为 2 列

发布于 2024-11-08 06:17:13 字数 1323 浏览 1 评论 0原文

我有一个 xslt 样式表,它根据是否存在图像将 xml 文件中的数据格式化为具有单列的表。由于数据量相当大,因此该列太长,我想尝试将当前列拆分为 2 个相等的列。知道我该怎么做吗?

    <?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<table border="0" bordercolor="#606060" style="width:200px">
  <tr bgcolor="white" width="200px">
  </tr>
  <xsl:for-each select="NewDataSet/Manufacturer">
    <tr>
      <xsl:choose>
        <xsl:when test="Image = 'none'">
          <td bgcolor="#dfdfdf">
            <a href="Vehicles.aspx?Manufacturer={ManufacturerID}" style="text-decoration:none;" runat="server">
              <xsl:value-of select="Manufacturer"/>
            </a>
          </td>
        </xsl:when>
        <xsl:otherwise>
          <td>
            <a href="Vehicles.aspx?Manufacturer={ManufacturerID}" style="text-decoration:none;" runat="server">
              <im alt="{Manufacturer}" src="Images/Manufacturers/{Image}" style="border-width: 0px; width: 50px; "/>
            </a>
          </td>
        </xsl:otherwise>
      </xsl:choose>
    </tr>
  </xsl:for-each>
</table>
</xsl:template>

I have an xslt style sheet that formats the data from my xml file into a table with a single column based on whether there is an image present or not. There is a fair amount of data so the column is too long though and i want to try splitting the current column into 2 equal columns. And idea how i can do this?

    <?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<table border="0" bordercolor="#606060" style="width:200px">
  <tr bgcolor="white" width="200px">
  </tr>
  <xsl:for-each select="NewDataSet/Manufacturer">
    <tr>
      <xsl:choose>
        <xsl:when test="Image = 'none'">
          <td bgcolor="#dfdfdf">
            <a href="Vehicles.aspx?Manufacturer={ManufacturerID}" style="text-decoration:none;" runat="server">
              <xsl:value-of select="Manufacturer"/>
            </a>
          </td>
        </xsl:when>
        <xsl:otherwise>
          <td>
            <a href="Vehicles.aspx?Manufacturer={ManufacturerID}" style="text-decoration:none;" runat="server">
              <im alt="{Manufacturer}" src="Images/Manufacturers/{Image}" style="border-width: 0px; width: 50px; "/>
            </a>
          </td>
        </xsl:otherwise>
      </xsl:choose>
    </tr>
  </xsl:for-each>
</table>
</xsl:template>

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

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

发布评论

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

评论(1

少年亿悲伤 2024-11-15 06:17:13

怎么样,

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
  <table border="0" bordercolor="#606060" style="width:200px">
    <tr bgcolor="white" width="200px">
    </tr>
    <tr>
    <xsl:for-each select="NewDataSet/Manufacturer">
        <xsl:choose>
            <xsl:when test="position() mod 2 = 0">
                <!-- so essentialy on even numbered elements process the current and next elements -->
                <td>
                    <xsl:call-template name="do-cell-content">
                        <xsl:with-param name="node" select="."/>
                    </xsl:call-template>
                </td>
                <td>
                    <xsl:call-template name="do-cell-content">
                        <xsl:with-param name="node" select="../Manufacturer[position()+1]"/>
                    </xsl:call-template>
                </td>
            <xsl:when>
        </xsl:choose>
    </xsl:for-each>
    </tr>
  </table>
</xsl:template>
</xsl:stylesheet>

我已经将示例中写入单元格内容的部分和 部分提取到另一个名为的 xsl:template do-cell-content

how about something like this

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
  <table border="0" bordercolor="#606060" style="width:200px">
    <tr bgcolor="white" width="200px">
    </tr>
    <tr>
    <xsl:for-each select="NewDataSet/Manufacturer">
        <xsl:choose>
            <xsl:when test="position() mod 2 = 0">
                <!-- so essentialy on even numbered elements process the current and next elements -->
                <td>
                    <xsl:call-template name="do-cell-content">
                        <xsl:with-param name="node" select="."/>
                    </xsl:call-template>
                </td>
                <td>
                    <xsl:call-template name="do-cell-content">
                        <xsl:with-param name="node" select="../Manufacturer[position()+1]"/>
                    </xsl:call-template>
                </td>
            <xsl:when>
        </xsl:choose>
    </xsl:for-each>
    </tr>
  </table>
</xsl:template>
</xsl:stylesheet>

I've extracted the part that writes the content of the cells and the <xsl:choose> part from your example to another xsl:template called do-cell-content

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