Note that there are some explanatory texts on larger screens.

plurals
  1. POxsl grouping of repetitive nodes by xml element in xslt1
    primarykey
    data
    text
    <p>I have a complex xml structure that looks like : </p> <pre><code> &lt;Items&gt; &lt;Item&gt; &lt;ItemTexts&gt; &lt;ItemText&gt; &lt;ItemTextsType&gt;type1&lt;/ItemTextsType&gt; &lt;ItemTextsTypeDesc&gt;description11&lt;/ItemTextsTypeDesc&gt; &lt;ItemTextsLine&gt;1&lt;/ItemTextsLine&gt; &lt;/ItemText&gt; &lt;ItemText&gt; &lt;ItemTextsType&gt;type1&lt;/ItemTextsType&gt; &lt;ItemTextsTypeDesc&gt;description12&lt;/ItemTextsTypeDesc&gt; &lt;ItemTextsLine&gt;2&lt;/ItemTextsLine&gt; &lt;/ItemText&gt; &lt;ItemText&gt; &lt;ItemTextsType&gt;type2&lt;/ItemTextsType&gt; &lt;ItemTextsTypeDesc&gt;description21&lt;/ItemTextsTypeDesc&gt; &lt;ItemTextsLine&gt;3&lt;/ItemTextsLine&gt; &lt;/ItemText&gt; &lt;ItemText&gt; &lt;ItemTextsType&gt;type2&lt;/ItemTextsType&gt; &lt;ItemTextsTypeDesc&gt;description22&lt;/ItemTextsTypeDesc&gt; &lt;ItemTextsLine&gt;4&lt;/ItemTextsLine&gt; &lt;/ItemText&gt; &lt;/ItemTexts&gt; &lt;/Item&gt; &lt;Item&gt; &lt;ItemTexts&gt; &lt;ItemText&gt; &lt;ItemTextsType&gt;type1&lt;/ItemTextsType&gt; &lt;ItemTextsTypeDesc&gt;description11&lt;/ItemTextsTypeDesc&gt; &lt;ItemTextsLine&gt;1&lt;/ItemTextsLine&gt; &lt;/ItemText&gt; &lt;ItemText&gt; &lt;ItemTextsType&gt;type1&lt;/ItemTextsType&gt; &lt;ItemTextsTypeDesc&gt;description12&lt;/ItemTextsTypeDesc&gt; &lt;ItemTextsLine&gt;2&lt;/ItemTextsLine&gt; &lt;/ItemText&gt; &lt;ItemText&gt; &lt;ItemTextsType&gt;type2&lt;/ItemTextsType&gt; &lt;ItemTextsTypeDesc&gt;description21&lt;/ItemTextsTypeDesc&gt; &lt;ItemTextsLine&gt;3&lt;/ItemTextsLine&gt; &lt;/ItemText&gt; &lt;ItemText&gt; &lt;ItemTextsType&gt;type2&lt;/ItemTextsType&gt; &lt;ItemTextsTypeDesc&gt;description22&lt;/ItemTextsTypeDesc&gt; &lt;ItemTextsLine&gt;4&lt;/ItemTextsLine&gt; &lt;/ItemText&gt; &lt;/ItemTexts&gt; &lt;/Item&gt; &lt;Item&gt; &lt;ItemTexts&gt; &lt;ItemText&gt; &lt;ItemTextsType&gt;type1&lt;/ItemTextsType&gt; &lt;ItemTextsTypeDesc&gt;description11&lt;/ItemTextsTypeDesc&gt; &lt;ItemTextsLine&gt;1&lt;/ItemTextsLine&gt; &lt;/ItemText&gt; &lt;ItemText&gt; &lt;ItemTextsType&gt;type1&lt;/ItemTextsType&gt; &lt;ItemTextsTypeDesc&gt;description12&lt;/ItemTextsTypeDesc&gt; &lt;ItemTextsLine&gt;2&lt;/ItemTextsLine&gt; &lt;/ItemText&gt; &lt;ItemText&gt; &lt;ItemTextsType&gt;type2&lt;/ItemTextsType&gt; &lt;ItemTextsTypeDesc&gt;description21&lt;/ItemTextsTypeDesc&gt; &lt;ItemTextsLine&gt;3&lt;/ItemTextsLine&gt; &lt;/ItemText&gt; &lt;ItemText&gt; &lt;ItemTextsType&gt;type2&lt;/ItemTextsType&gt; &lt;ItemTextsTypeDesc&gt;description22&lt;/ItemTextsTypeDesc&gt; &lt;ItemTextsLine&gt;4&lt;/ItemTextsLine&gt; &lt;/ItemText&gt; &lt;/ItemTexts&gt; &lt;/Item&gt; &lt;Item&gt; &lt;ItemTexts&gt; &lt;ItemText&gt; &lt;ItemTextsType&gt;type3&lt;/ItemTextsType&gt; &lt;ItemTextsTypeDesc&gt;description31&lt;/ItemTextsTypeDesc&gt; &lt;ItemTextsLine&gt;1&lt;/ItemTextsLine&gt; &lt;/ItemText&gt; &lt;ItemText&gt; &lt;ItemTextsType&gt;type3&lt;/ItemTextsType&gt; &lt;ItemTextsTypeDesc&gt;description32&lt;/ItemTextsTypeDesc&gt; &lt;ItemTextsLine&gt;2&lt;/ItemTextsLine&gt; &lt;/ItemText&gt; &lt;ItemText&gt; &lt;ItemTextsType&gt;type2&lt;/ItemTextsType&gt; &lt;ItemTextsTypeDesc&gt;description21&lt;/ItemTextsTypeDesc&gt; &lt;ItemTextsLine&gt;3&lt;/ItemTextsLine&gt; &lt;/ItemText&gt; &lt;ItemText&gt; &lt;ItemTextsType&gt;type2&lt;/ItemTextsType&gt; &lt;ItemTextsTypeDesc&gt;description22&lt;/ItemTextsTypeDesc&gt; &lt;ItemTextsLine&gt;4&lt;/ItemTextsLine&gt; &lt;/ItemText&gt; &lt;/ItemTexts&gt; &lt;/Item&gt; &lt;/Items&gt; </code></pre> <p>I run with xsl on each Item like :</p> <pre><code>&lt;xsl:for-each select="Items/Item"&gt; </code></pre> <p>I need an example of how to group <code>&lt;ItemText&gt;</code> by <code>&lt;ItemTextsType&gt;</code> individually for each <code>&lt;Item&gt;</code> so the outcome will be like :</p> <p>For first <code>&lt;Item&gt;</code> in this example :</p> <blockquote> <p><strong>type1</strong> </p> <pre><code>description11 description12 </code></pre> <p><strong>type2</strong></p> <p>description21</p> <p>description22</p> </blockquote> <p>For second <code>Item</code> in this example :</p> <blockquote> <p><strong>type3</strong> </p> <pre><code>description31 description32 </code></pre> <p><strong>type2</strong></p> <p>description21</p> <p>description22</p> </blockquote> <p>of course I will arrange the outcome in a table like :</p> <pre><code>&lt;table width="100%" border="1" style="display: block;"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td id="SelectedRowLinkageContents"&gt; &lt;table width="100%" dir="ltr"&gt; &lt;tbody&gt; &lt;tr style="background-color: #507CD1; text-align: center"&gt; &lt;td colspan="3" style="font: bold; color: white"&gt; Item1 &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td style="height: 35px; font: bold; color: #507CD1;"&gt; type1 &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt; desription11 &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt; desription12 &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td style="height: 35px; font: bold; color: #507CD1;"&gt; type2 &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt; desription21 &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt; desription22 &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt; desription23 &lt;/td&gt; &lt;/tr&gt; &lt;/tbody&gt; &lt;/table&gt; &lt;table width="100%" dir="ltr"&gt; &lt;tbody&gt; &lt;tr style="background-color: #507CD1; text-align: center"&gt; &lt;td colspan="3" style="font: bold; color: white"&gt; Item2 &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td style="height: 35px; font: bold; color: #507CD1;"&gt; type1 &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt; desription11 &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt; desription12 &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td style="height: 35px; font: bold; color: #507CD1;"&gt; type2 &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt; desription21 &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt; desription23 &lt;/td&gt; &lt;/tr&gt; &lt;/tbody&gt; &lt;/table&gt; &lt;table width="100%" dir="ltr"&gt; &lt;tbody&gt; &lt;tr style="background-color: #507CD1; text-align: center"&gt; &lt;td colspan="3" style="font: bold; color: white"&gt; Item3 &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td style="height: 35px; font: bold; color: #507CD1;"&gt; type1 &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt; desription11 &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt; desription12 &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td style="height: 35px; font: bold; color: #507CD1;"&gt; type2 &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt; desription21 &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt; desription23 &lt;/td&gt; &lt;/tr&gt; &lt;/tbody&gt; &lt;/table&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/tbody&gt; &lt;/table&gt; </code></pre> <p>The point is that there is separate grouping for each <code>&lt;Item&gt;</code> into it's own <code>&lt;table&gt;</code> and inside that <code>&lt;table&gt;</code> there is groupping by <code>&lt;ItemTextsType&gt;</code></p> <p>I have tried something like </p> <pre><code>&lt;xsl:key name="item-texts-type" match="ItemText" use="ItemTextsType" /&gt; &lt;xsl:for-each select="ItemTexts/ItemText[count(. | key('item-texts-type', ItemTextsType)[1]) = 1]"&gt; &lt;xsl:sort select="ItemTextsType" /&gt; &lt;tr&gt; &lt;td style ="height:35px;font: bold; color:#507CD1;"&gt; &lt;xsl:value-of select="ItemTextsType" /&gt; &lt;/td&gt; &lt;/tr&gt; &lt;xsl:for-each select="key('item-texts-type', ItemTextsType)"&gt; &lt;tr&gt; &lt;td&gt; &lt;xsl:value-of select="ItemTextsTypeDesc" /&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/xsl:for-each&gt; &lt;/xsl:for-each&gt; </code></pre> <p>but it only work on <strong>non</strong> repetitive nodes (if there were only one <code>&lt;Item&gt;</code>it would work fine). <strong>I can't change xml because it comes from customer .</strong></p> <p>Please help me , I need it ASAP .</p> <p>Thank you !!!! </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload