Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8830165
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T08:00:32+00:00 2026-06-14T08:00:32+00:00

I have a complex xml structure that looks like : <Items> <Item> <ItemTexts> <ItemText>

  • 0

I have a complex xml structure that looks like :

  <Items>
      <Item>
          <ItemTexts>
            <ItemText>
              <ItemTextsType>type1</ItemTextsType>
              <ItemTextsTypeDesc>description11</ItemTextsTypeDesc>
              <ItemTextsLine>1</ItemTextsLine>
            </ItemText>
            <ItemText>
              <ItemTextsType>type1</ItemTextsType>
              <ItemTextsTypeDesc>description12</ItemTextsTypeDesc>
              <ItemTextsLine>2</ItemTextsLine>
            </ItemText>
            <ItemText>
              <ItemTextsType>type2</ItemTextsType>
              <ItemTextsTypeDesc>description21</ItemTextsTypeDesc>
              <ItemTextsLine>3</ItemTextsLine>
            </ItemText>
            <ItemText>
              <ItemTextsType>type2</ItemTextsType>
              <ItemTextsTypeDesc>description22</ItemTextsTypeDesc>
              <ItemTextsLine>4</ItemTextsLine>
            </ItemText>
          </ItemTexts>
         </Item>
    <Item>
          <ItemTexts>
            <ItemText>
              <ItemTextsType>type1</ItemTextsType>
              <ItemTextsTypeDesc>description11</ItemTextsTypeDesc>
              <ItemTextsLine>1</ItemTextsLine>
            </ItemText>
            <ItemText>
              <ItemTextsType>type1</ItemTextsType>
              <ItemTextsTypeDesc>description12</ItemTextsTypeDesc>
              <ItemTextsLine>2</ItemTextsLine>
            </ItemText>
            <ItemText>
              <ItemTextsType>type2</ItemTextsType>
              <ItemTextsTypeDesc>description21</ItemTextsTypeDesc>
              <ItemTextsLine>3</ItemTextsLine>
            </ItemText>
            <ItemText>
              <ItemTextsType>type2</ItemTextsType>
              <ItemTextsTypeDesc>description22</ItemTextsTypeDesc>
              <ItemTextsLine>4</ItemTextsLine>
            </ItemText>
          </ItemTexts>
         </Item>
<Item>
          <ItemTexts>
            <ItemText>
              <ItemTextsType>type1</ItemTextsType>
              <ItemTextsTypeDesc>description11</ItemTextsTypeDesc>
              <ItemTextsLine>1</ItemTextsLine>
            </ItemText>
            <ItemText>
              <ItemTextsType>type1</ItemTextsType>
              <ItemTextsTypeDesc>description12</ItemTextsTypeDesc>
              <ItemTextsLine>2</ItemTextsLine>
            </ItemText>
            <ItemText>
              <ItemTextsType>type2</ItemTextsType>
              <ItemTextsTypeDesc>description21</ItemTextsTypeDesc>
              <ItemTextsLine>3</ItemTextsLine>
            </ItemText>
            <ItemText>
              <ItemTextsType>type2</ItemTextsType>
              <ItemTextsTypeDesc>description22</ItemTextsTypeDesc>
              <ItemTextsLine>4</ItemTextsLine>
            </ItemText>
          </ItemTexts>
         </Item>
    <Item>
          <ItemTexts>
            <ItemText>
              <ItemTextsType>type3</ItemTextsType>
              <ItemTextsTypeDesc>description31</ItemTextsTypeDesc>
              <ItemTextsLine>1</ItemTextsLine>
            </ItemText>
            <ItemText>
              <ItemTextsType>type3</ItemTextsType>
              <ItemTextsTypeDesc>description32</ItemTextsTypeDesc>
              <ItemTextsLine>2</ItemTextsLine>
            </ItemText>
            <ItemText>
              <ItemTextsType>type2</ItemTextsType>
              <ItemTextsTypeDesc>description21</ItemTextsTypeDesc>
              <ItemTextsLine>3</ItemTextsLine>
            </ItemText>
            <ItemText>
              <ItemTextsType>type2</ItemTextsType>
              <ItemTextsTypeDesc>description22</ItemTextsTypeDesc>
              <ItemTextsLine>4</ItemTextsLine>
            </ItemText>
          </ItemTexts>
         </Item>
    </Items>

Each <Item> has MANY more xml elements , but I won’t specify them now.

I run with xsl on each Item like :

<xsl:for-each select="Items/Item">

and I produce table with rows for each <Item> and many <td> in each row.

I need an example of how to group <ItemText> by <ItemTextsType> individually for each <Item> .

I will arrange the outcome in a table like :

 <table>
    <%--tr for each Item in Items--%>
    <tr>
        <td>
            some value from xml element according <b> Item1 </b>
        </td>
        <td>
            some more value from xml element according <b> Item1 </b>
        </td>
        <%--
        .
        .
        .
--%>
        <td>
            <table width="100%" dir="ltr">
                <tbody>
                    <tr style="background-color: #507CD1; text-align: center">
                        <td colspan="3" style="font: bold; color: white">
                            Item1
                        </td>
                    </tr>
                    <tr>
                        <td style="height: 35px; font: bold; color: #507CD1;">
                            type1
                        </td>
                    </tr>
                    <tr>
                        <td>
                            description11
                        </td>
                    </tr>
                    <tr>
                        <td>
                            description12
                        </td>
                    </tr>
                    <tr>
                        <td style="height: 35px; font: bold; color: #507CD1;">
                            type2
                        </td>
                    </tr>
                    <tr>
                        <td>
                            description21
                        </td>
                    </tr>
                    <tr>
                        <td>
                            description22
                        </td>
                    </tr>
                </tbody>
            </table>
        </td>
        <td>
            even more value from xml element according <b> Item1 </b>
        </td>
        <%--
        .
        .
        .
        --%>
    </tr>
   <tr>
        <td>
            some value from xml element according <b> Item2 </b>
        </td>
        <td>
            some more value from  xml element according <b> Item2 </b>
        </td>
        <%--
        .
        .
        .
--%>
        <td>
            <table width="100%" dir="ltr">
                <tbody>
                    <tr style="background-color: #507CD1; text-align: center">
                        <td colspan="3" style="font: bold; color: white">
                            Item2
                        </td>
                    </tr>
                    <tr>
                        <td style="height: 35px; font: bold; color: #507CD1;">
                            type1
                        </td>
                    </tr>
                    <tr>
                        <td>
                            description11
                        </td>
                    </tr>
                    <tr>
                        <td>
                            description12
                        </td>
                    </tr>
                    <tr>
                        <td style="height: 35px; font: bold; color: #507CD1;">
                            type2
                        </td>
                    </tr>
                    <tr>
                        <td>
                            description21
                        </td>
                    </tr>
                    <tr>
                        <td>
                            description22
                        </td>
                    </tr>
                </tbody>
            </table>
        </td>
        <td>
            even more value from according <b> Item2 </b>
        </td>
        <%--
        .
        .
        .
        --%>
    </tr>
   <%-- and so on--%>
</table>

The point is that there is separate grouping for each <Item> into it’s own <tr><td><table> and inside that <table> there is groupping by <ItemTextsType>

I have tried something like

<xsl:key name="item-texts-type" match="ItemText" use="ItemTextsType" />


<xsl:for-each select="ItemTexts/ItemText[count(. | key('item-texts-type', ItemTextsType)[1]) = 1]">

                        <xsl:sort select="ItemTextsType" />
                        <tr>
                          <td style ="height:35px;font: bold; color:#507CD1;">
                            <xsl:value-of select="ItemTextsType" />
                          </td>
                        </tr>

                        <xsl:for-each select="key('item-texts-type', ItemTextsType)">
                          <tr>
                            <td>
                               <xsl:value-of select="ItemTextsTypeDesc" />
                            </td>
                          </tr>
                        </xsl:for-each>


                      </xsl:for-each>

but it only work on non repetitive nodes (if there were only one <Item>it would work fine).
I can’t change xml because it comes from customer .

Please help me , I need it ASAP .

Thank you !!!!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T08:00:33+00:00Added an answer on June 14, 2026 at 8:00 am

    If you want a separate grouping for each Item then one way to achieve that would be to include some unique identifier for the containing Item as part of the key value, e.g.

    <xsl:key name="item-texts-type" match="ItemText"
             use="concat(generate-id(ancestor::Item), '|', ItemTextsType)" />
    
    <!-- assuming the context node is the current Item -->
    <xsl:variable name="currentItemId" select="generate-id()" />
    
    <xsl:for-each select="ItemTexts/ItemText[count(. | key('item-texts-type',
            concat($currentItemId, '|', ItemTextsType))[1]) = 1]">
      <!-- .... -->
      <xsl:for-each select="key('item-texts-type',
            concat($currentItemId, '|', ItemTextsType))">
    

    This would be much more straightforward if you could use XSLT 2.0 of course…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a complex Clojure data structure that I would like to serialize -
I have a dataset that I read in from a complex xml structure.... here
I have a number rather large, complex xml documents that I need to loop
I have a very complex task - create a software that imports XMl files
I have a complex graph of XML-serializable classes that I'm able to (de)serialize to
i have complex XML structure i want get all descendents uisng some xml paren.child.@attribute
I have a complex structure xml from which I need to read some element
Consider that I have a complex class structure where many elements inherit from other
I have a complex XSD schema and hundreds of XML files conforming to the
I have an xml with an xml-schema. The xml-schema defines an abstract complex type

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.