[英]XSLT adding a tr at nth position while transforming the XML node with different child nodes
我是XSLT的新手,我正在尝试转换以下XML。 请注意,子节点将有所不同
<parent>
<child1>A</child1>
<child2>B</child2>
<child3>C</child3>
<child4>D</child4>
<child5>E</child5>
<child6>F</child6>
<child7>G</child7>
</parent>
当n为3时,我想将上面的转换如下
<tr><td>child1:A</td><td>child2:B</td><td>child3:C</td></tr>
<tr><td>child4:D</td><td>child5:E</td><td>child6:F</td></tr>
<tr><td>child7:G</td></tr>
我尝试如下
<xsl:template match="parent/*[position() mod 4 = 1]">
<tr>
<xsl:apply-templates mode="proc"
select=".|following-sibling::parent/*[not(position() > 3)]"
/>
</tr>
</xsl:template>
<xsl:template match="parent/*[not(position() mod 4 = 1)]"/>
<xsl:template match="parent/*" mode="proc">
<td class="label"><xsl:value-of select ="name(.)"/>:<xsl:value-of select ="."/></td>
</xsl:template>
问题是这条线...
<xsl:apply-templates mode="proc"
select=".|following-sibling::parent/*[not(position() > 3)]" />
您在与父元素的子元素( parent/*)
匹配的模板中。 这意味着当前节点没有parent
节点作为同级节点。 将表达式更改为此
<xsl:apply-templates mode="proc"
select=".|following-sibling::*[not(position() > 3)]" />
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.