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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T18:53:26+00:00 2026-05-20T18:53:26+00:00

During transformation, who I can combine one node into another. for example, when Attributes/Attribute/Type=ComplexAttr

  • 0

During transformation, who I can combine one node into another. for example, when Attributes/Attribute/Type=ComplexAttr then it should go under Attributes/Attribute/Type=Common only.
Below is the sample XML & XSLT that I’m trying to use which is not working. TIA (Thanks in Advance)

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:key name="type" match="Attribute" use="Type"/>
    <xsl:template match="/">
        <Data Schema="XML A">
            <xsl:apply-templates select="XML/Attributes/Attribute">
                <xsl:sort select="Type" order="descending"/>
            </xsl:apply-templates>
            <errorCodes>
                <xsl:apply-templates select="XML/Attributes/Attribute"
                                     mode="errors"/>
            </errorCodes>
        </Data>
    </xsl:template>
    <xsl:template
            match="Attribute[generate-id()=generate-id(key('type', Type)[1])]">
        <xsl:if test="Type != 'ComplexAttr'">
            <Attributes type="{Type}">
                <xsl:if test="Type = 'ComplexAttr'">
                    <xsl:value-of select="Common"/>
                </xsl:if>
                <xsl:apply-templates select="../Attribute[Type=current()/Type]" mode="out"/>
            </Attributes>           
        </xsl:if>
    </xsl:template>
    <xsl:template match="Attribute" mode="out">
        <Attr id="{id}" name="{Name}" value="{Value}"/>
    </xsl:template>
    <xsl:template match="Attribute"/>
    <xsl:template match="Attribute" mode="errors"/>
    <xsl:template match="Attribute[Value='']" mode="errors">
        <errorCode>"value for <xsl:value-of select="Name"/> is missing."</errorCode>
    </xsl:template>
    <xsl:template match="/Attribute">
        <xsl:if test="Type = 'ComplexAttr'">
            <Attributes type="Common">
                <xsl:apply-templates select="../Attribute[Type=current()/Type]" mode="out"/>
                <!--<Attr id="{id}" name="{Name}" value="{Value}"/>-->
            </Attributes>
        </xsl:if>
    </xsl:template>
</xsl:stylesheet>

—- Source XML —-

<?xml version="1.0" encoding="windows-1252"?>
<XML>
    <Attributes>
        <Attribute>
            <id>5</id>
            <Name>Buyer ID</Name>
            <Type>common</Type>
            <Value>Lee</Value>
        </Attribute>
        <Attribute>
            <id>331</id>
            <Name>Enviornment</Name>
            <Type>common</Type>
            <Value>Development</Value>
        </Attribute>
        <Attribute>
            <id>79</id>
            <Name>Retail</Name>
            <Type>common</Type>
            <Value></Value>
        </Attribute>
        <Attribute>
            <id>402</id>
            <Name>Gender</Name>
            <Type>category</Type>
            <Value>Men</Value>
        </Attribute>
    <Attribute>
         <id>1197</id> 
         <Name>UPC</Name> 
         <Type>ComplexAttr</Type> 
         <Value>Testing</Value> 
         <Path /> 
    </Attribute>
    </Attributes>
</XML>

—- Transformed XML output

<?xml version="1.0" encoding="utf-8"?>
<Data Schema="XML A">
  <Attributes type="common">
    <Attr id="5" name="Buyer ID" value="Lee" />
    <Attr id="331" name="Enviornment" value="Development" />
    <Attr id="79" name="Retail" value="" />
    <Attr id="41" name="PlusShip" value="False" />
    <Collection id="" name="test">
      <ComplexAttr refId="0">
        <MaskValue />
        <Attr id="1197" name="UPC" value="Testing" />
      </ComplexAttr>
    </Collection>
  </Attributes>
  <Attributes type="category">
    <Attr id="402" name="Gender" value="Men" />
    <Attr id="433" name="HeelHeight" value="" />
  </Attributes>
  <errorCodes>
    <errorCode>"value for Retail is missing."</errorCode>
  </errorCodes>
</Data>
  • 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-20T18:53:27+00:00Added an answer on May 20, 2026 at 6:53 pm

    If you want to group Attribute by Type with 'common' and 'ComplexAttr' in the same group, then you need to change the key value expression into something like:

    <xsl:key name="type" 
             match="Attribute" 
             use="concat(
                     Type[. != 'ComplexAttr'],
                     substring(
                        'common',
                        1 div (Type = 'ComplexAttr')
                     )
                  )"/> 
    
    <xsl:template match="Attribute[
                            generate-id()
                             = generate-id(
                                  key('type',
                                      concat(
                                         Type[. != 'ComplexAttr'],
                                         substring(
                                            'common',
                                            1 div (Type = 'ComplexAttr')
                                         )
                                      )
                                  )[1]
                               )
                         ]">       
    

    EDIT: And in the group templates applying:

    <xsl:apply-templates select="key('type',
                                     concat(
                                        Type[. != 'ComplexAttr'],
                                        substring(
                                           'common',
                                           1 div (Type = 'ComplexAttr')
                                        )
                                     )
                                 )" 
                         mode="out"/> 
    

    EDIT: Full example. This stylesheet:

    <!DOCTYPE xsl:stylesheet [
    <!ENTITY key "concat(Type[. != 'ComplexAttr'],substring('common',1 div (Type = 'ComplexAttr')))">
    ]>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
        <xsl:key name="type" match="Attribute" use="&key;"/>
        <xsl:template match="/">
            <Data Schema="XML A">
                <xsl:apply-templates
                     select="XML/Attributes/Attribute[
                                generate-id() = generate-id(key('type', &key;)[1])
                             ]">
                    <xsl:sort select="&key;" order="descending"/>
                </xsl:apply-templates>
                <errorCodes>
                    <xsl:apply-templates select="XML/Attributes/Attribute"
                                         mode="errors"/>
                </errorCodes>
            </Data>
        </xsl:template>
        <xsl:template match="Attribute">
            <xsl:variable name="vCurrent-Grouping-Key" select="&key;"/>
            <Attributes type="{$vCurrent-Grouping-Key}">
                <xsl:apply-templates select="key('type',$vCurrent-Grouping-Key)"
                                     mode="out"/>
            </Attributes>
        </xsl:template>
        <xsl:template match="Attribute" mode="out" name="makeAttr">
            <Attr id="{id}" name="{Name}" value="{Value}"/>
        </xsl:template>
        <xsl:template match="Attribute[Type='ComplexAttr']" mode="out">
            <Collection id="" name="test">
                <ComplexAttr refId="0">
                    <MaskValue />
                    <xsl:call-template name="makeAttr"/>
                </ComplexAttr>
            </Collection>
        </xsl:template>
        <xsl:template match="Attribute" mode="errors"/>
        <xsl:template match="Attribute[Value='']" mode="errors">
            <errorCode>"value for <xsl:value-of select="Name"/> is missing."</errorCode>
        </xsl:template>
    </xsl:stylesheet>
    

    Output:

    <Data Schema="XML A">
        <Attributes type="common">
            <Attr id="5" name="Buyer ID" value="Lee" />
            <Attr id="331" name="Enviornment" value="Development" />
            <Attr id="79" name="Retail" value="" />
            <Collection id="" name="test">
                <ComplexAttr refId="0">
                    <MaskValue />
                    <Attr id="1197" name="UPC" value="Testing" />
                </ComplexAttr>
            </Collection>
        </Attributes>
        <Attributes type="category">
            <Attr id="402" name="Gender" value="Men" />
        </Attributes>
        <errorCodes>
            <errorCode>"value for Retail is missing."</errorCode>
        </errorCodes>
    </Data>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

During the installation of Apache2 I got the following message into cmd window: Installing
During execution, how can a java program tell how much memory it is using?
During conversion old, 2008 database project into 2010 database project using features like Partial
I am using identity transformation and during this based on a condition, I need
There are two XSL files. One includes another using an <xsl:include> . The main
During a recent peer review, another Software Engineer suggested that I state that the
RubyMine can toggle block syntax between do;end and { } block notation. For example,
During the serialization we can use either memory stream or file stream. What is
During my insertion of case when statement, the oracle will auto insert another '0'
I'm using a Matrix to set a transformation on my Graphics object during OnPaint

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.