简体   繁体   English

XML 到 XSLT - 问题 - 重复 XML 元素

[英]XML to XSLT - Question - Repeating XML Elements

I have data that comes in from the XML like this....我有像这样来自 XML 的数据....

   <DetailLine><FormField><Name>Vendor Item</Name> 
   <DisplayValue>0201029</DisplayValue><Value /><Value2 /> 
   </FormField><FormField><Name>Item Description</Name> 
   <DisplayValue>BOX JUNCTION HF AHC5111 10X10X</DisplayValue> 
   <Value>BOX JUNCTION HF AHC5111 10X10X</Value><Value2 />
    <DetailLine><FormField><Name>Vendor Item</Name> 
   <DisplayValue>0201040</DisplayValue><Value /><Value2 /> 
   </FormField><FormField><Name>Item Description</Name> 
   <DisplayValue>BOX JUNCTION HF A201608LP 20 X</DisplayValue> 
   <Value>BOX JUNCTION HF A201608LP 20 X</Value><Value2 />

I can code it in the XSLT like this, and as long as I know exactly how many lines I have, it works....我可以像这样在 XSLT 中编码,只要我确切知道我有多少行,它就可以工作....

<xsl:for-each 
  select="GeneratedDocument/Detail/DetailLine[10]/FormField">
<td>
<xsl:value-of select="DisplayValue"/>
</td>
</xsl:for-each>

But I want it to be smarter and just say for each detail line, put 10 display values and go to the next row.但我希望它更聪明,只是说对于每个详细信息行,将 10 个显示值和 go 放到下一行。

Any ideas?有任何想法吗? Thanks.谢谢。

I want to return all the display values into each column and create a new row for each new detail line.我想将所有显示值返回到每一列中,并为每个新的详细信息行创建一个新行。

Each detail line has fixed 10 display values.每个明细行有固定的 10 个显示值。

Sorry for all edits.抱歉所有编辑。 New here.新来的。

Hope this code produces the output:希望此代码生成 output:

<xsl:template match="GeneratedDocument">
    <table>
        <xsl:for-each select="Detail/DetailLine">
            <tr>
                <xsl:for-each select="FormField">
                    <td>
                        <xsl:value-of select="DisplayValue"/>
                    </td>
                </xsl:for-each>
            </tr>
        </xsl:for-each>
    </table>
</xsl:template>

This code creates a table element and uses two nested "for-each" loops.此代码创建一个表元素并使用两个嵌套的“for-each”循环。 The outer loop iterates over each "DetailLine" element within the "Detail" element.外部循环遍历“Detail”元素中的每个“DetailLine”元素。 For each "DetailLine" element, the inner loop iterates over each "FormField" element within the "DetailLine" element, and creates a table cell (td element) with the "DisplayValue" element of the current "FormField" element.对于每个“DetailLine”元素,内部循环遍历“DetailLine”元素中的每个“FormField”元素,并使用当前“FormField”元素的“DisplayValue”元素创建一个表格单元格(td 元素)。 The inner loop will run for each "FormField" element and will create a new column for each one of them.内部循环将为每个“FormField”元素运行,并为每个元素创建一个新列。 The outer loop will run for each "DetailLine" element and will create a new row for each one of them.外循环将为每个“DetailLine”元素运行,并为每个元素创建一个新行。 This way, it will have 10 columns for each row, and the "DisplayValue" element will be the content of each column.这样,每行将有 10 列,“DisplayValue”元素将是每列的内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM