[英]XSLT adding a tr at nth position while transforming the XML node with different child nodes
I am new to XSLT, and I am trying to transform the below XML. 我是XSLT的新手,我正在尝试转换以下XML。 Note that the child nodes will be different
请注意,子节点将有所不同
<parent>
<child1>A</child1>
<child2>B</child2>
<child3>C</child3>
<child4>D</child4>
<child5>E</child5>
<child6>F</child6>
<child7>G</child7>
</parent>
I want transform the above as follows,when n is 3 当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>
I tried as follows 我尝试如下
<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>
The problem is with this line... 问题是这条线...
<xsl:apply-templates mode="proc"
select=".|following-sibling::parent/*[not(position() > 3)]" />
You are in a template matching a child of the parent element ( parent/*)
. 您在与父元素的子元素(
parent/*)
匹配的模板中。 This means the current node does not have a parent
node as a sibling. 这意味着当前节点没有
parent
节点作为同级节点。 Change the expression to this 将表达式更改为此
<xsl:apply-templates mode="proc"
select=".|following-sibling::*[not(position() > 3)]" />
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.