我有以下问题: 在xsd中,它说:
<xs:element name="somevalue" type="ait2:eic" maxOccurs="unbounded">
<xs:annotation>
<xs:documentation>Field No. 41</xs:documentation>
</xs:annotation>
</xs:element>
对我来说意味着字段41可以存在多次(字段39或42仅允许一次)。我有一个实际的例子(来自xml):
<somevalue>12323K</somevalue>
<somevalue>12324I</somevalue>
因为它不是自己的序列 - 每个都不可能(或者我错了?)。 到目前为止,我的代码看起来像这样(xslt),它只涵盖了第一次出现:
<tr>
<td>41</td>
<td>Some value</td>
<td>
<xsl:value-of select="//somevalue"/>
</td>
</tr>
如何拥有一个重复组?所以每个人都有一些价值观。将进入。
THX!
编辑:代码示例
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="#nsc"?>
<xsl:stylesheet id="nsc" version="1.0" xmlns:data="http://www.acer.europa.eu/REMIT/TestTable_V1.xsd" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<data:data>
<TestTable>
<TradeList>
<nonStandardContractReport>
<settlementMethod>P</settlementMethod>
<deliveryPointOrZone>12323K</deliveryPointOrZone>
<deliveryPointOrZone>12324I</deliveryPointOrZone>
<deliveryStartDate>2022-01-01</deliveryStartDate>
<deliveryEndDate>2023-01-01</deliveryEndDate>
<loadType>GD</loadType>
<actionType>N</actionType>
</nonStandardContractReport>
</TradeList>
</TestTable>
</data:data>
<xsl:template match="/xsl:stylesheet">
<xsl:apply-templates select="data:data/*" />
</xsl:template>
<xsl:template match="TestTable">
<html>
<table border="0" style="border-collapse:collapse;">
<body>
<tr>
<td>40</td>
<td>Option strike price</td>
<td>
<xsl:value-of select="//optionDetails/optionStrikePrice"/>
</td>
</tr>
<tr>
<th/>
<th>Delivery profile</th>
<th/>
</tr>
<tr>
<td>41</td>
<td>Delivery point or zone</td>
<td>
<xsl:value-of select="//deliveryPointOrZone"/>
</td>
</tr>
<tr>
<td>42</td>
<td>Delivery start date</td>
<td>
<xsl:value-of select="//deliveryStartDate"/>
</td>
</tr>
<tr>
<td>43</td>
<td>Delivery end date</td>
<td>
<xsl:value-of select="//deliveryEndDate"/>
</td>
</tr>
<tr>
<td>44</td>
<td>Load type</td>
<td>
<xsl:value-of select="//loadType"/>
</td>
</tr>
<tr>
<th/>
<th>Life cycle information</th>
<th/>
</tr>
<tr>
<td>45</td>
<td>Action type</td>
<td>
<xsl:value-of select="//actionType"/>
</td>
</tr>
</body>
</table>
</html>
</xsl:template>
答案 0 :(得分:0)
考虑以下示例:
<强> XML 强>
<root>
<alpha>10</alpha>
<bravo>20</bravo>
<bravo>21</bravo>
<bravo>22</bravo>
<charlie>30</charlie>
</root>
XSLT 1.0
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" encoding="utf-8" />
<xsl:template match="/root">
<table border="1">
<tr>
<td>A</td>
<td>Prima</td>
<td>
<xsl:value-of select="alpha"/>
</td>
</tr>
<xsl:for-each select="bravo">
<tr>
<td>B</td>
<td>Secunda</td>
<td>
<xsl:value-of select="."/>
</td>
</tr>
</xsl:for-each>
<tr>
<td>C</td>
<td>Tertia</td>
<td>
<xsl:value-of select="charlie"/>
</td>
</tr>
</table>
</xsl:template>
</xsl:stylesheet>
<强>结果强>
<table border="1">
<tr>
<td>A</td>
<td>Prima</td>
<td>10</td>
</tr>
<tr>
<td>B</td>
<td>Secunda</td>
<td>20</td>
</tr>
<tr>
<td>B</td>
<td>Secunda</td>
<td>21</td>
</tr>
<tr>
<td>B</td>
<td>Secunda</td>
<td>22</td>
</tr>
<tr>
<td>C</td>
<td>Tertia</td>
<td>30</td>
</tr>
</table>
呈现为:
请注意,使用更优雅的方法可以获得相同的结果:
XSLT 1.0
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" encoding="utf-8" />
<xsl:template match="/root">
<table border="1">
<xsl:apply-templates/>
</table>
</xsl:template>
<xsl:template match="alpha">
<tr>
<td>A</td>
<td>Prima</td>
<td>
<xsl:value-of select="."/>
</td>
</tr>
</xsl:template>
<xsl:template match="bravo">
<tr>
<td>B</td>
<td>Secunda</td>
<td>
<xsl:value-of select="."/>
</td>
</tr>
</xsl:template>
<xsl:template match="charlie">
<tr>
<td>C</td>
<td>Tertia</td>
<td>
<xsl:value-of select="."/>
</td>
</tr>
</xsl:template>
</xsl:stylesheet>