English 中文(简体)
利用xsl填充单行,填写在html表中
原标题:Using xsl to fill in empty rows in a html table

I want to create multiple html table pages using XML as the input and xsl as the transformation language. Now these tables should always have a fixed height, whether it s just one row or ten. I can t get it to work with CSS (min-height). So I was wondering, if it is possible to get xsl to always output ten rows and add empty rows in case there are less then ten rows or adding rows in case there are more then ten rows existent in the XML and therefore resizing the table.

Any ideas how this can be achieved?

最佳回答

你肯定能够这样做。 我可以显示,如果你没有足够的话,你将数据分成几张表格,每张有十头row(或可能是唯一的一只)的row子。 它应当帮助你去做你们需要去做的事情(没有XML投入和希望的超文本产出就象我可以做的那样)。

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

    <xsl:output method="html" encoding="UTF-8"/>

    <xsl:template match="/">
        <xsl:apply-templates select="data/row[position() mod 10 = 1]" mode="newtable"/>
    </xsl:template>

    <xsl:template match="row" mode="newtable">
        <table>
            <xsl:apply-templates select="."/>
            <xsl:apply-templates select="following-sibling::row[position() &lt; 10]"/>
            <xsl:call-template name="dummy-rows">
                <xsl:with-param 
                       name="how-many" 
                       select="9 - count(following-sibling::row[position() &lt; 10])"/>
            </xsl:call-template>
        </table>
    </xsl:template>

    <xsl:template match="row">
        <tr><td><xsl:value-of select="."/></td></tr>
    </xsl:template>

    <xsl:template name="dummy-rows">
        <xsl:param name="how-many" select="0"/>
        <xsl:if test="$how-many &gt; 0">
            <tr><td>dummy</td></tr>
            <xsl:call-template name="dummy-rows">
                <xsl:with-param name="how-many" select="$how-many - 1"/>
            </xsl:call-template>
        </xsl:if>
    </xsl:template>
</xsl:stylesheet>

想法是,你开始使用每组10的“第一”代号。 The s[position() mod 10 = 1]migration. 当你坐在桌子上时,你会打上桌子,以正常方式重新打开。 然后,你接下9个数据流。 最后,你补充说,你们需要确保每个桌子的总数达到10个点。 <代码>dummy-rows的模板是一次回收。 因此,这里有两个技术:通过<条码>(>) mo/条码(<>)分立,并使用<条码>recursion实施该编码。

<>>>>> 如果你只需要确保你在桌旁至少拥有十几行,那么你就不需要分开逻辑:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

    <xsl:output method="html" encoding="UTF-8"/>

    <xsl:template match="/">
        <table>
            <xsl:apply-templates select="data/row"/>
            <xsl:call-template name="dummy-rows">
                <xsl:with-param 
                    name="how-many" 
                    select="10 - count(data/row)"/>
            </xsl:call-template>
        </table>
    </xsl:template>

    <xsl:template match="row">
        <tr><td><xsl:value-of select="."/></td></tr>
    </xsl:template>

    <xsl:template name="dummy-rows">
        <xsl:param name="how-many" select="0"/>
        <xsl:if test="$how-many &gt; 0">
            <tr><td>dummy</td></tr>
            <xsl:call-template name="dummy-rows">
                <xsl:with-param name="how-many" select="$how-many - 1"/>
            </xsl:call-template>
        </xsl:if>
    </xsl:template>
</xsl:stylesheet>

你们可以通过这样的投入努力:

<data>
  <row>1</row>
  <row>1</row>
  <row>3</row>
</data>

或提供这种投入:

<data>
    <row>1</row>
    <row>2</row>
    <row>3</row>
    <row>4</row>
    <row>5</row>
    <row>6</row>
    <row>7</row>
    <row>8</row>
    <row>9</row>
    <row>10</row>
    <row>11</row>
    <row>12</row>
</data>

在这两种情况下,结果都是预期的。 引证。 你们应该能够从这里来。

问题回答

暂无回答




相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

image changed but appears the same in browser

I m writing a php script to crop an image. The script overwrites the old image with the new one, but when I reload the page (which is supposed to pickup the new image) I still see the old one. ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签