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 5991229
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T23:21:25+00:00 2026-05-22T23:21:25+00:00

I want to use XSLT to modify : <Office Code=1 OtherAttribute=5> <Customer CustomerId=0010 CodeModifier=A/>

  • 0

I want to use XSLT to modify :

<Office Code="1" OtherAttribute="5">
   <Customer CustomerId="0010" CodeModifier="A"/>
   <Customer CustomerId="0011" CodeModifier="B"/>
   <Customer CustomerId="0012" CodeModifier="B"/>
</Office>
<Office Code="2" OtherAttribute="6">
   <Customer CustomerId="2010" CodeModifier="A"/>
   <Customer CustomerId="0011" CodeModifier="C"/>
</Office>

into :

<Office Code="1A" OtherAttribute="5">
   <Customer CustomerId="0010"/>
</Office>
<Office Code="1B" OtherAttribute="5">
   <Customer CustomerId="0011"/>
   <Customer CustomerId="0012"/>
</Office>
<Office Code="2A" OtherAttribute="6">
   <Customer CustomerId="2010"/>
</Office>
<Office Code="2C" OtherAttribute="6">
   <Customer CustomerId="0011"/>
</Office>

My goals :

  • group every Customer entity with the same CodeModifier into Office entities. If there are some multiple CodeModifier, I will add Office entity. The Code attribute into Office will be modified (concatenation of CodeModifier of Client into the Office)
  • (facultative but trivial I think) suppress the CodeModifier attribute and keep all other attribute

Does someone know how to do that ?

  • 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-05-22T23:21:26+00:00Added an answer on May 22, 2026 at 11:21 pm

    Here’s another approach, using matching templates only.


    Tested as XSLT 1.0 under MSXSL 4.0

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >
        <xsl:output method="xml" indent="yes"/>
    
        <xsl:key name="kCustomerGroup" match="Customer" 
            use="concat(../@Code, @CodeModifier)" 
            />
    
        <xsl:template match="Office">
            <xsl:apply-templates select="Customer[generate-id() 
                =
                generate-id(key('kCustomerGroup', 
                concat(../@Code, @CodeModifier))[1])]"
                />
        </xsl:template>
    
        <xsl:template match="Customer">
            <Office 
                Code="{concat(../@Code,@CodeModifier)}" 
                OtherAttribute="{../@OtherAttribute}">
    
                <xsl:apply-templates select="key('kCustomerGroup', 
                    concat(../@Code,@CodeModifier))" mode="copy"/>
    
            </Office>
        </xsl:template>
    
        <xsl:template match="Customer" mode="copy">
            <xsl:copy>
                <xsl:copy-of select="@CustomerId"/>
            </xsl:copy>
        </xsl:template>
    
    </xsl:stylesheet>
    

    Outputs to:

    <?xml version="1.0" encoding="UTF-8"?>
    <Office Code="1A" OtherAttribute="5">
       <Customer CustomerId="0010"/>
    </Office>
    <Office Code="1B" OtherAttribute="5">
       <Customer CustomerId="0011"/>
       <Customer CustomerId="0012"/>
    </Office>
    <Office Code="2A" OtherAttribute="6">
       <Customer CustomerId="2010"/>
    </Office>
    <Office Code="2C" OtherAttribute="6">
       <Customer CustomerId="0011"/>
    </Office>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to use XSLT to transform a set of documents into one structure.
this is my xml file. i want to use xslt to transfer them into
I have an XML document with un-namespaced elements, and I want to use XSLT
I want to create conditional comments in XSLT. But when I use this: <!--
Is it possible to use XSLT to transform XML into something other than XML?
I want to use XSLT to calculate the summation value of amount the input
I use XSLT as a code generator for various components, including other XSLT. For
I have an xml element: <myElement>item1 item2 item3</myElement> I want to use XSLT to
I want to use JavaScript to show my XSLT, but on my server nothing
I want to perform an XSLT 2.0 transformation by the use of command line

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.