簡體   English   中英

XSLT在第n個位置添加tr,同時使用不同的子節點轉換XML節點

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM