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

  • SEARCH
  • Home
  • 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 8676693
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T20:15:45+00:00 2026-06-12T20:15:45+00:00

I have this xml file: <?xml version=1.0 encoding=UTF-8?> <o-com-inter xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance version=1> <rules deplVer=125> <cre-det-r

  • 0

I have this xml file:

<?xml version="1.0" encoding="UTF-8"?>
<o-com-inter xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1">
<rules deplVer="125">
<cre-det-r name="Auto_R_1">
    <act>false</act>
    <thres-curr>000</thres-curr>
    <thress>
        <thres name="Auto_R_125_1">
            <sco>11111</sco>
            <serv-res>
                <serv-res>ABC</serv-res>
            </serv-res>
            <cat>
                <cate>CatA</cate>
            </cat>
            <o-ru-con>
                <co-ru-con b-name="InterMge" name="ac_T_EQ_000">
                    <si-ru-con>
                        <ru-con-ite>
                            <ru-con-ite-lit>
                                <nae1>ac</nae1>
                                <ope>T_EQ</ope>
                                <val1>000</val1>
                            </ru-con-ite-lit>
                            <bId>2</bId>
                        </ru-con-ite>
                    </si-ru-con>
                </co-ru-con>
                <co-ru-con b-name="InterMge" name="ac_T_EQ_001">
                    <si-ru-con>
                        <ru-con-ite>
                            <ru-con-ite-lit>
                                <nae1>ac</nae1>
                                <ope>T_EQ</ope>
                                <val1>001</val1>
                            </ru-con-ite-lit>
                            <bId>2</bId>
                        </ru-con-ite>
                    </si-ru-con>
                </co-ru-con>
                <co-ru-con b-name="InterMge" name="tra_T_EQ_014">
                    <si-ru-con>
                        <ru-con-ite>
                            <ru-con-ite-lit>
                                <nae1>tra</nae1>
                                <ope>T_EQ</ope>
                                <val1>014</val1>
                            </ru-con-ite-lit>
                            <bId>3</bId>
                        </ru-con-ite>
                    </si-ru-con>
                </co-ru-con>
                <co-ru-con b-name="InterMge" name="tra_T_EQ_015">
                    <si-ru-con>
                        <ru-con-ite>
                            <ru-con-ite-lit>
                                <nae1>tra</nae1>
                                <ope>T_EQ</ope>
                                <val1>015</val1>
                            </ru-con-ite-lit>
                            <bId>3</bId>
                        </ru-con-ite>
                    </si-ru-con>
                </co-ru-con>
            </o-ru-con>
            <al>true</al>
        </thres>
    </thress>
    <description> rSId=125 Fp=0.1234567 Dr=1.0 
        rSId=48 SFp=1.0 SDr=1.0_2012-10-10T09:55:09+02:00
    </description>
  </cre-det-r>
  <cre-det-r>
    ....If this block exists, it will contain the same elements as above in the same order, otherwise, this block doesn't exists and the code contains only the preceding "cre-det-r" block.
  </cre-det-r>
 </rules>
</o-com-inter>

I want to check the value of each bId element. If this value is the same with the preceding or following bId element in the o-ru-con element, then I will group all the different co-ru-con block (in the whole block o-ru-con) with the same value of bId in one co-ru-con as shown in the expected output file.
I tried to use this xsl file:

<xsl:stylesheet 
 version="1.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:strip-space elements="*"/>
<xsl:output indent="yes"/>
<!--  -->
<xsl:template match="*">
<xsl:copy>
    <xsl:copy-of select="@*"/>
    <xsl:apply-templates/>
</xsl:copy>
</xsl:template> 

<xsl:key name="k1"
match="ru-con-ite-lit[bId = preceding-sibling::ru-con-ite-lit[1]/bId]"
use="generate-id(preceding-sibling::ru-con-ite-lit[not(bId = preceding-sibling::ru-con-ite-lit[1]/bId)][1])"/>

<xsl:template match="ru-con-ite">
<xsl:copy>
    <xsl:copy-of select="@*"/>
    <xsl:apply-templates select="ru-con-ite-lit[not(preceding-sibling::ru-con-ite-lit[1]) or not(bId = preceding-sibling::ru-con-ite-lit[1]/bId)]"/>
  </xsl:copy>
</xsl:template>

<xsl:template match="ru-con-ite-lit">
<xsl:copy>
    <xsl:copy-of select="@*"/>
 <!--     <xsl:apply-templates/>-->

    <xsl:apply-templates select=". | key('k1', generate-id())" mode="sp"/>

 </xsl:copy>
</xsl:template>

<xsl:template match="ru-con-ite-lit" mode="sp">

    <xsl:copy-of select="node()[not(self::bId)]"/>

 </xsl:template>

</xsl:stylesheet>

I can remove the element bId in my xml file with this xsl file, but I cann’t group the different co-ru-con block with the same value of bId in one co-ru-con block. The expected output will look like this:

<?xml version="1.0" encoding="UTF-8"?>
<o-com-inter xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1">
<rules deplVer="125">
<cre-det-r name="Auto_R_1">
    <act>false</act>
    <thres-curr>000</thres-curr>
    <thress>
        <thres name="Auto_R_125_1">
            <sco>11111</sco>
            <serv-res>
                <serv-res>ABC</serv-res>
            </serv-res>
            <cat>
                <cate>CatA</cate>
            </cat>
            <o-ru-con>
                <co-ru-con b-name="InterMge" name="bId2"><!-- the value of name here has been changed by the tag-name "bId" and the value 2 of this one -->
                    <si-ru-con>
                        <ru-con-ite>
                            <ru-con-ite-lit>
                                <nae1>ac</nae1>
                                <ope>T_EQ</ope>
                                <val1>000</val1>
                            </ru-con-ite-lit>
                            <!-- Here was the element <bId> with the value 2 and this has been deleted after the transformation -->
                        </ru-con-ite>
                    </si-ru-con>
                    <si-ru-con>
                        <ru-con-ite>
                            <ru-con-ite-lit>
                                <nae1>ac</nae1>
                                <ope>T_EQ</ope>
                                <val1>001</val1>
                            </ru-con-ite-lit>
                            <!-- Here was the element <bId> with the value 2 and this has been deleted after the transformation -->
                        </ru-con-ite>
                    </si-ru-con>
                </co-ru-con>
                <co-ru-con b-name="InterMge" name="bId3"><!-- the value of name here has been changed by the tag-name "bId" and the value 3 of this one -->
                    <si-ru-con>
                        <ru-con-ite>
                            <ru-con-ite-lit>
                                <nae1>tra</nae1>
                                <ope>T_EQ</ope>
                                <val1>014</val1>
                            </ru-con-ite-lit>
                            <!-- Here was the element <bId> with the value 3and this has been deleted after the transformation -->
                        </ru-con-ite>
                    </si-ru-con>
                    <si-ru-con>
                        <ru-con-ite>
                            <ru-con-ite-lit>
                                <nae1>tra</nae1>
                                <ope>T_EQ</ope>
                                <val1>015</val1>
                            </ru-con-ite-lit>
                            <!-- Here was the element <bId> with thw value 3 and this has been deleted after the transformation -->
                        </ru-con-ite>
                    </si-ru-con>
                </co-ru-con>
            </o-ru-con>
            <al>true</al>
        </thres>
    </thress>
    <description> rSId=125 Fp=0.1234567 Dr=1.0 
        rSId=48 SFp=1.0 SDr=1.0_2012-10-10T09:55:09+02:00
    </description>
</cre-det-r>
<cre-det-r>
    ....If this block exists, it will contain the same elements as above in the same order, otherwise, this block doesn't exists and the code contains only the preceding "cre-det-r" block.
</cre-det-r>

Thanks

  • 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-12T20:15:46+00:00Added an answer on June 12, 2026 at 8:15 pm

    This looks like a grouping issue, and in XSLT1.0 this is a job for Muenchian Grouping. In your case you are grouping co-run-con elements by a combination of there parent o-ru-con element, and their descendant bId element. Therefore you would start by defining a key for this

    <xsl:key 
       name="con" 
       match="co-ru-con" 
       use="concat(generate-id(..), '|', si-ru-con/ru-con-ite/bId)" />
    

    Then, whenever you match a o-ru-con element, you would then match distinct co-ru-con by looking for such elements that were the first occurence of that element in the key

    <xsl:apply-templates 
       select="co-ru-con
          [generate-id() 
             = generate-id(key('con', concat(generate-id(..), '|', si-ru-con/ru-con-ite/bId))[1])]" />
    

    This would allow you to create a single co-ru-con element for the group. You would then match the child si-ru-con elements for the group like so

    <xsl:apply-templates 
     select="key('con', concat(generate-id(..), '|', si-ru-con/ru-con-ite/bId))/si-ru-con" />
    

    Here is the full XSLT

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
       <xsl:output method="xml" indent="yes"/>
       <xsl:strip-space elements="*" />
       <xsl:key name="con" match="co-ru-con" use="concat(generate-id(..), '|', si-ru-con/ru-con-ite/bId)" />
    
       <xsl:template match="o-ru-con">
          <o-ru-con>
             <xsl:apply-templates select="co-ru-con[generate-id() = generate-id(key('con', concat(generate-id(..), '|', si-ru-con/ru-con-ite/bId))[1])]" />
          </o-ru-con>
       </xsl:template>
    
       <xsl:template match="co-ru-con">
          <co-ru-con b-name="{@b-name}" bId="{si-ru-con/ru-con-ite/bId}">
             <xsl:apply-templates select="key('con', concat(generate-id(..), '|', si-ru-con/ru-con-ite/bId))/si-ru-con" />
          </co-ru-con>
       </xsl:template>
    
       <xsl:template match="bId" />
    
       <xsl:template match="@*|node()">
          <xsl:copy>
             <xsl:apply-templates select="@*|node()"/>
          </xsl:copy>
       </xsl:template>
    </xsl:stylesheet>
    

    When applied to your sample XML, the following is output

    <o-com-inter version="1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
       <rules deplVer="125">
          <cre-det-r name="Auto_R_1">
             <act>false</act>
             <thres-curr>000</thres-curr>
             <thress>
                <thres name="Auto_R_125_1">
                   <sco>11111</sco>
                   <serv-res>
                      <serv-res>ABC</serv-res>
                   </serv-res>
                   <cat>
                      <cate>CatA</cate>
                   </cat>
                   <o-ru-con>
                      <co-ru-con b-name="InterMge" bId="2">
                         <si-ru-con>
                            <ru-con-ite>
                               <ru-con-ite-lit>
                                  <nae1>ac</nae1>
                                  <ope>T_EQ</ope>
                                  <val1>000</val1>
                               </ru-con-ite-lit>
                            </ru-con-ite>
                         </si-ru-con>
                         <si-ru-con>
                            <ru-con-ite>
                               <ru-con-ite-lit>
                                  <nae1>ac</nae1>
                                  <ope>T_EQ</ope>
                                  <val1>001</val1>
                               </ru-con-ite-lit>
                            </ru-con-ite>
                         </si-ru-con>
                      </co-ru-con>
                      <co-ru-con b-name="InterMge" bId="3">
                         <si-ru-con>
                            <ru-con-ite>
                               <ru-con-ite-lit>
                                  <nae1>tra</nae1>
                                  <ope>T_EQ</ope>
                                  <val1>014</val1>
                               </ru-con-ite-lit>
                            </ru-con-ite>
                         </si-ru-con>
                         <si-ru-con>
                            <ru-con-ite>
                               <ru-con-ite-lit>
                                  <nae1>tra</nae1>
                                  <ope>T_EQ</ope>
                                  <val1>015</val1>
                               </ru-con-ite-lit>
                            </ru-con-ite>
                         </si-ru-con>
                      </co-ru-con>
                   </o-ru-con>
                   <al>true</al>
                </thres>
             </thress>
             <description> rSId=125 Fp=0.1234567 Dr=1.0 rSId=48 SFp=1.0 SDr=1.0_2012-10-10T09:55:09+02:00 </description>
          </cre-det-r>
          <cre-det-r> ....If this block exists, it will contain the same elements as above in the same order, otherwise, this block doesn't exists and the code contains only the preceding "cre-det-r" block. </cre-det-r>
       </rules>
    </o-com-inter>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this xml file <?xml version=1.0 encoding=UTF-8?> <bo:C837ClaimParent xsi:type=bo:C837ClaimParent xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance xmlns:bo=http://somelongpathHere/process/bo> <claimAux> ...
I have xml file like this <?xml version=1.0 encoding=UTF-8?> <specification xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance xsi:noNamespaceSchemaLocation=file://Desktop/normal.xsd> <university> <refstr>bdvl_te_skrm_stc</refstr>
I have this XML at http://localhost/file.xml : <?xml version=1.0 encoding=utf-8?> <val:Root xmlns:val=http://www.hw-group.com/XMLSchema/ste/values.xsd> <Agent> <Version>2.0.3</Version>
I have this simple XML file : <?xml version=1.0 encoding=utf-8 ?> <Artists> <artist artistId=1>
I have this data from a xml file: <?xml version=1.0 encoding=utf-8 ?> <words> <id>...</id>
I have this SVG file: <?xml version=1.0 encoding=utf-8?> <!-- Generator: Adobe Illustrator 15.0.0, SVG
I have an xml file which looks like this <?xml version=1.0 encoding=UTF-8 ?> <BulkDataExchangeRequests
Here's an example of an XML file created in InfoPath: <?xml version=1.0 encoding=UTF-8?> <?mso-infoPathSolution
I have downloaded this extension from http://www.blueflyingfish.com/orgchart/index.php?option=com_orgchart&view=entitytree&Itemid=53 for organizational chart . My Joomla version
I have this xml file which has text init. i.e Hi my name is

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.