【问题标题】:Facing challenge populating html table using XSLT面临使用 XSLT 填充 html 表的挑战
【发布时间】:2019-12-10 12:29:58
【问题描述】:

以下数据来自数据库,

姓名指定工资离职

Vignesh SE 50000 技术

vivah SSE 100000 技术指标

这我必须使用 xslt 填充到 html 表中,如下表形式。在这里我应该也可以读取列名。

名字 vignesh vivah

名称 SE SSE

工资50000 100000

离开技术技术

通过查看一些参考资料,我尝试了这样的做法,

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:template match="/">
    <html>
        <head>
            <title/>
            <style type="text/css">
                table.ma-temp-data-table {
                    margin:5px;
                }
                .ma-temp-data-table tr:nth-of-type(odd) {
                        background-color:#eee;
                    }
                .ma-temp-data-table tr:nth-of-type(even) {
                        background-color:#ddd;
                    }
                .ma-temp-data-table th {
                        background-color:#ccc;
                    }
                .ma-temp-data-table td {
                    padding: 2px;
                }
                .ma-temp-data-table th {
                    padding: 4px;
                    font-weight: bold;
                }
            </style>
        </head>
        <body>
            <table class="ma-temp-data-table">
                <xsl:variable name="rowdata" select="root/row"/>

                <xsl:for-each select="$rowdata">
                <tr>

                    <xsl:for-each select="$rowdata">

                        <xsl:variable name="pos" select="position()"/>

                        <td style="font-weight:bold"><xsl:value-of select="$rowdata[$pos]"/></td>

                    </xsl:for-each>
                </tr>
            </table>
        </body>
    </html>
</xsl:template> 

表格是这样填充的,

VigneshSE50000技术 vivahSSE100000技术

这里的问题是列空间没有出现。 我是 XSLT 的新手,谁能帮忙实现一下。

【问题讨论】:

    标签: xml xslt


    【解决方案1】:

    这是我的解决方案,有些我能够找到它。

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output omit-xml-declaration="yes" indent="yes"/>
    <xsl:template match="/">
        <html>
            <head>
                <title/>
                <style type="text/css">
                    table.ma-temp-data-table {
                        margin:5px;
                    }
                    .ma-temp-data-table tr:nth-of-type(odd) {
                            background-color:#eee;
                        }
                    .ma-temp-data-table tr:nth-of-type(even) {
                            background-color:#ddd;
                        }
                    .ma-temp-data-table th {
                            background-color:#ccc;
                        }
                    .ma-temp-data-table td {
                        padding: 2px;
                    }
                    .ma-temp-data-table th {
                        padding: 4px;
                        font-weight: bold;
                    }
                </style>
            </head>
            <body>
                <table class="ma-temp-data-table">
                    <xsl:variable name="rowdata" select="root/row"/>
    
    
                    <tr>
                        <th>Field Name</th>
                        <th>Current Version</th>
                        <th>Previous Version</th>
                        <th>Original Version</th>
    
                    </tr>
    
                    <xsl:for-each select="$rowdata">
    
    
                    <xsl:if test="position()=1">
                        <xsl:for-each select="*[local-name() != 'event_type'][text()]">
                                <xsl:call-template name="output_row">
                                    <xsl:with-param name="rowdata" select="$rowdata"/>  
                                    <xsl:with-param name="fieldname" select="local-name()"/>
                                    <xsl:with-param name="fieldvalue" select="text()"/>
                                </xsl:call-template>
                            </xsl:for-each>
                        </xsl:if>
                    </xsl:for-each>
    
                </table>
            </body>
        </html>
    </xsl:template>
    
    <xsl:template name="output_row">
        <xsl:param name="rowdata"/>
        <xsl:param name="fieldname"/>
        <xsl:param name="fieldvalue"/>
        <tr>
            <td>
                <xsl:value-of select="$fieldname"/>
            </td>
            <td>
                <xsl:value-of select="$fieldvalue"/>
            </td>
    
            <!--<td>
            <xsl:if test="$fieldname='status'">
                <xsl:value-of select="$fieldname"/>
            </xsl:if>
            <xsl:if test="$fieldname!='status'">
                empty
            </xsl:if>
            </td>-->
    
            <xsl:for-each select="$rowdata">
    
                <xsl:if test="position()>1">
                    <xsl:variable name="prevrowpos" select="position()-1"/>
    
                    <td>
                        <!--<xsl:if test="./*[local-name()=$fieldname]/text() != $rowdata[$prevrowpos]/*[local-name()=$fieldname]/text() ">-->
    
                            <xsl:variable name="datavalue" select="./*[local-name()=$fieldname]/text()"/>
                            <xsl:value-of select="$datavalue"/>     
                        <!--</xsl:if>-->    
                    </td>
                </xsl:if>
            </xsl:for-each>
    
        </tr>
    </xsl:template>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-11-12
      • 2014-08-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-12-16
      • 1970-01-01
      相关资源
      最近更新 更多