Xml 无法读取xsl中的值 波动 1209180044- 4. 波动 1209180045- 1. xslt 2020年4月5日处理结果

Xml 无法读取xsl中的值 波动 1209180044- 4. 波动 1209180045- 1. xslt 2020年4月5日处理结果,xml,xslt,Xml,Xslt,*输出 标题| schbat | pck|u cnt 波浪| 1209180044-| 4 波浪| 1209180045-| 1 根据列数,我将在行中进行归档(意味着如果元数据中的列数为3,那么我将在行元素中进行归档。但我无法读取这些归档的值(每次我这样做时,我总是得到wave结果) < p>您的样式表期望顶级元素为“代码> MOCA结果”,但实际上是“代码>结果< /代码> .< /P> < P>我感觉您过于复杂了。请考虑下面的例子: XML <?xml version="1.0" en

*输出

标题| schbat | pck|u cnt
波浪| 1209180044-| 4
波浪| 1209180045-| 1


根据列数,我将在行中进行归档(意味着如果元数据中的列数为3,那么我将在行元素中进行归档。但我无法读取这些归档的值(每次我这样做时,我总是得到wave结果)

< p>您的样式表期望顶级元素为“代码> MOCA结果”,但实际上是“代码>结果< /代码> .< /P> < P>我感觉您过于复杂了。请考虑下面的例子:

XML

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
   <xsl:key name="kString" match="field" use="."/>
   <xsl:template match="/">
      <html>
         <body style="text-align: center;">
           <table width="450" cellpadding="5" cellspacing="0" style="border: 1px solid #CCCCCC" >
           <thead>
                <tr>
                    <th colspan="5" bgcolor="#FFFFFF" style="font-family: 'Arial', sans-serif; color: #ba1e29; border-bottom: 2px solid #ffffff; border-right: 2px solid #ffffff;"><span style="font-family: 'Oswald', sans-serif; text-align: center; font-weight: 500; color: #3f3f3f; line-height: 1; margin-bottom: 1rem; text-transform: uppercase;"><strong>Results For Processing on <span style="color: #ba1e29">5-4-2020</span></strong></span></th>
                </tr>
                <xsl:variable name="set" select="moca-results/metadata/column" />
                <xsl:variable name="count" select="count($set)" />

                <tr>
                <xsl:for-each select="$set">
                    <th width="20%" style="font-size:13px;font-family: 'Arial', sans-serif;background-color: #f0f0fa; color: #ba1e29; border-bottom: 2px solid #ffffff; border-right: 2px solid #ffffff;"><xsl:value-of select="@name" /></th>
                </xsl:for-each>
                </tr>

            </thead>
            <tbody>
                <xsl:variable name="bodyset" select="results/data/row" />
                <xsl:variable name="bodycount" select="count($bodyset)" />
                <xsl:variable name="set" select="results/metadata/column" />
                <xsl:variable name="count" select="count($set)" />
                <xsl:for-each select="$bodyset">
                    <tr>
                       <xsl:for-each select="$set">
                        <td align="center" style="font-family: 'Arial', sans-serif;background-color: #f0f0fa; color: #414143; border-right: 2px solid #ffffff;">
                            <xsl:value-of select="filed" />
                        </td>
                    </xsl:for-each>
                    </tr>
                </xsl:for-each>
            </tbody>
            </table>
         </body>
      </html>
   </xsl:template>
</xsl:stylesheet>

波动
1209180044-
4.
波动
1209180045-
1.
XSLT1.0

<results>
  <metadata>
    <column name="title" type="S" length="4000" nullable="true" />
    <column name="schbat" type="S" length="32" nullable="true" />
    <column name="pck_cnt" type="I" length="4" nullable="true" />
  </metadata>
  <data>
    <row>
      <field>Wave</field>
      <field>1209180044-</field>
      <field>4</field>
    </row>
    <row>
      <field>Wave</field>
      <field>1209180045-</field>
      <field>1</field>
    </row>
  </data>
</results>

结果

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/results">
    <html>
        <body>
            <table border="1">
                <thead>
                    <tr>
                        <xsl:for-each select="metadata/column">
                            <th>
                                <xsl:value-of select="@name" />
                            </th>
                        </xsl:for-each>
                    </tr>
                </thead>
            <tbody>
                <xsl:for-each select="data/row">
                    <tr>
                       <xsl:for-each select="field">
                            <td>
                                <xsl:value-of select="." />
                            </td>
                        </xsl:for-each>
                    </tr>
                </xsl:for-each>
            </tbody>
            </table>
        </body>
    </html>
</xsl:template>

</xsl:stylesheet>

标题
施巴特
pck_cnt
波动
1209180044-
4.
波动
1209180045-
1.
渲染:


请将当前XSLT和预期输出添加到问题中。为什么需要列计数?不是每行都有相同的字段吗?为什么不为每行创建一个单元格?对不起,我错了,忘了删除moca@michael.hor257k基于列计数,它将定义有多少个字段应该是它们的内部行element@michael.hor257k 我修改了列数,并尝试将wave作为3个文件的输出。这并不能回答这个问题。若要评论或要求作者澄清,请在他们的帖子下方留下评论。-我不同意。问题是转换不起作用,我已经给出了不起作用的原因。
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/results">
    <html>
        <body>
            <table border="1">
                <thead>
                    <tr>
                        <xsl:for-each select="metadata/column">
                            <th>
                                <xsl:value-of select="@name" />
                            </th>
                        </xsl:for-each>
                    </tr>
                </thead>
            <tbody>
                <xsl:for-each select="data/row">
                    <tr>
                       <xsl:for-each select="field">
                            <td>
                                <xsl:value-of select="." />
                            </td>
                        </xsl:for-each>
                    </tr>
                </xsl:for-each>
            </tbody>
            </table>
        </body>
    </html>
</xsl:template>

</xsl:stylesheet>
<html>
   <body>
      <table>
         <thead>
            <tr>
               <th>title</th>
               <th>schbat</th>
               <th>pck_cnt</th>
            </tr>
         </thead>
         <tbody>
            <tr>
               <td>Wave</td>
               <td>1209180044-</td>
               <td>4</td>
            </tr>
            <tr>
               <td>Wave</td>
               <td>1209180045-</td>
               <td>1</td>
            </tr>
         </tbody>
      </table>
   </body>
</html>