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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T07:43:32+00:00 2026-06-11T07:43:32+00:00

This is my first time posting here, so I apologize in advance for the

  • 0

This is my first time posting here, so I apologize in advance for the length and for any format issue or lack of information. I’ve been working on this problem for a few days and I’ve researched my problem extensively but haven’t found a solution yet, so I am hoping someone here can help me. It’s an xslt related issue and I only started coding in xslt a couple of months ago so I’m not so experienced.

Basically, I have an input XML which may contain duplicate records as well as empty tags and I need to reorganize them into a javascript associative array to be able to manipulate and display the values efficiently on the client side.

My question is: Is there a way to do a multilevel grouping even if the used field tag is empty. If not, is there a way I can edit the xml in xsl by replacing the empty tag with a keyword and then applying the rest of my templates?

To understand my problem here are the details.
This is my input XML

<cds>
    <sections>
        <section name="myteam_CurrentAgeCompleteSection" link="false">
            <detail name="">
                <record>
                    <field name="AGERANGEID">30-39</field>
                    <field name="NUMOFCOUNTAGE">1</field>
                    <field name="ORGUNITID">00001001</field>
                    <field name="PARENTORGUNITID">00000100</field>
                    <field name="ORGUNITNAME">Human Resources</field>
                </record>
                <record>
                    <field name="AGERANGEID">&gt;=70</field>
                    <field name="NUMOFCOUNTAGE">5</field>
                    <field name="ORGUNITID">00001001</field>
                    <field name="PARENTORGUNITID">00000100</field>
                    <field name="ORGUNITNAME">Human Resources</field>
                </record>
            </detail>
        </section>
        <section name="myteam_CurrentGenderCompleteSection" link="false">
            <detail name="">
                <record>
                    <field name="PARENTORGUNITID">00000100</field>
                    <field name="ORGUNITID">00001001</field>
                    <field name="ORGUNITNAME">Human Resources</field>
                    <field name="NUMOFGENDERCOUNT">5</field>
                    <field name="GENDER">2</field>
                </record>
                <record>
                    <field name="PARENTORGUNITID">00000100</field>
                    <field name="ORGUNITID">00001001</field>
                    <field name="ORGUNITNAME">Human Resources</field>
                    <field name="NUMOFGENDERCOUNT">7</field>
                    <field name="GENDER">1</field>
                </record>
            </detail>
        </section>
        <section name="myteam_CurrentRaceCompleteSection" link="false">
            <detail name="">
                <record>
                    <field name="ORGUNITNAME">Human Resources</field>
                    <field name="PARENTORGUNITID">00000100</field>
                    <field name="ORGUNITID">00001001</field>
                    <field name="NUMOFRACE">10.0</field>
                    <field name="RACENAME" />
                </record>
                <record>
                    <field name="ORGUNITNAME">Human Resources</field>
                    <field name="PARENTORGUNITID">00000100</field>
                    <field name="ORGUNITID">00001001</field>
                    <field name="NUMOFRACE">1</field>
                    <field name="RACENAME">Asian</field>
                </record>
                <record>
                    <field name="ORGUNITNAME">Human Resources</field>
                    <field name="PARENTORGUNITID">00000100</field>
                    <field name="ORGUNITID">00001001</field>
                    <field name="NUMOFRACE">1</field>
                    <field name="RACENAME">American Indian</field>
                </record>
            </detail>
        </section>
        <section name="myteam_ChildAgeColumnSection" link="false">
            <detail name="">
                <record>
                    <field name="AGERANGEID">40-49</field>
                    <field name="NUMOFCOUNTAGE">1</field>
                    <field name="ORGUNITID">50000013</field>
                    <field name="PARENTORGUNITID">00001001</field>
                    <field name="ORGUNITNAME">IT computer center (D)</field>
                </record>
                <record>
                    <field name="AGERANGEID">50-59</field>
                    <field name="NUMOFCOUNTAGE">2</field>
                    <field name="ORGUNITID">50000013</field>
                    <field name="PARENTORGUNITID">00001001</field>
                    <field name="ORGUNITNAME">IT computer center (D)</field>
                </record>
                <record>
                    <field name="AGERANGEID">&gt;=70</field>
                    <field name="NUMOFCOUNTAGE">5</field>
                    <field name="ORGUNITID">50000013</field>
                    <field name="PARENTORGUNITID">00001001</field>
                    <field name="ORGUNITNAME">IT computer center (D)</field>
                </record>
            </detail>
        </section>

        <section name="myteam_ChildGenderColumnSection" link="false">
            <detail name="">
                <record>
                    <field name="PARENTORGUNITID">00001001</field>
                    <field name="ORGUNITID">50000013</field>
                    <field name="ORGUNITNAME">IT computer center (D)</field>
                    <field name="NUMOFGENDERCOUNT">4</field>
                    <field name="GENDER">2</field>
                </record>
                <record>
                    <field name="PARENTORGUNITID">00001001</field>
                    <field name="ORGUNITID">50000147</field>
                    <field name="ORGUNITNAME">Personnel Administration (D)</field>
                    <field name="NUMOFGENDERCOUNT">3</field>
                    <field name="GENDER">1</field>
                </record>
                <record>
                    <field name="PARENTORGUNITID">00001001</field>
                    <field name="ORGUNITID">50000013</field>
                    <field name="ORGUNITNAME">IT computer center (D)</field>
                    <field name="NUMOFGENDERCOUNT">4</field>
                    <field name="GENDER">1</field>
                </record>
            </detail>
        </section>
        <section name="myteam_ChildGenderColumnSection" link="false">
            <detail name="">
                <record>
                    <field name="PARENTORGUNITID">00001001</field>
                    <field name="ORGUNITID">50000013</field>
                    <field name="ORGUNITNAME">IT computer center (D)</field>
                    <field name="NUMOFGENDERCOUNT">4</field>
                    <field name="GENDER">2</field>
                </record>
                <record>
                    <field name="PARENTORGUNITID">00001001</field>
                    <field name="ORGUNITID">50000147</field>
                    <field name="ORGUNITNAME">Personnel Administration (D)</field>
                    <field name="NUMOFGENDERCOUNT">3</field>
                    <field name="GENDER">1</field>
                </record>
                <record>
                    <field name="PARENTORGUNITID">00001001</field>
                    <field name="ORGUNITID">50000013</field>
                    <field name="ORGUNITNAME">IT computer center (D)</field>
                    <field name="NUMOFGENDERCOUNT">4</field>
                    <field name="GENDER">1</field>
                </record>
            </detail>
        </section>
        <section name="myteam_ChildGenderColumnSection" link="false">
            <detail name="">
                <record>
                    <field name="PARENTORGUNITID">00001001</field>
                    <field name="ORGUNITID">50000013</field>
                    <field name="ORGUNITNAME">IT computer center (D)</field>
                    <field name="NUMOFGENDERCOUNT">4</field>
                    <field name="GENDER">2</field>
                </record>
                <record>
                    <field name="PARENTORGUNITID">00001001</field>
                    <field name="ORGUNITID">50000147</field>
                    <field name="ORGUNITNAME">Personnel Administration (D)</field>
                    <field name="NUMOFGENDERCOUNT">3</field>
                    <field name="GENDER">1</field>
                </record>
            </detail>
        </section>
    </sections>
</cds>

I looked online and found that the best way to deal with multilevel grouping is to use xsl:key and generate-id(). That worked great and the data came out exactly as I wanted to, so the flow of my xsl is correct. But unfortunately if the field used in the xsl:key is an empty tag, when I go into the multilevel grouping using concat(), it fails.

<!-- Start external variables -->   
<!-- Field names -->
<xsl:variable name="ageFieldName" select="'AGERANGEID'" />
<xsl:variable name="genderFieldName" select="'GENDER'" />
<xsl:variable name="raceFieldName" select="'RACENAME'" />
<xsl:variable name="ouIdFieldName" select="'ORGUNITID'" />
<xsl:variable name="ouNameFieldName" select="'ORGUNITNAME'" />

<!-- Keys -->   
<xsl:key use="field[@name='AGERANGEID']" name="AGERANGEID" match="detail/record" />
<xsl:key use="concat(field[@name='AGERANGEID'],'|', field[@name='ORGUNITID'])" name="AGERANGEID_merge" match="detail/record" />
<xsl:key use="field[@name='GENDER']" name="GENDER" match="detail/record" />
<xsl:key use="concat(field[@name='GENDER'],'|', field[@name='ORGUNITID'])" name="GENDER_merge" match="detail/record" />
<xsl:key use="field[@name='RACENAME']" name="RACENAME" match="detail/record" />
<xsl:key use="concat(field[@name='RACENAME'],'|', field[@name='ORGUNITID'])" name="RACENAME_merge" match="detail/record" />

<xsl:key use="field[@name='ORGUNITID']" name="ORGUNITID" match="detail/record" />


<xsl:template match="/">
    var analyticsMap = {<xsl:call-template name="buildAnalyticsTable" />};
</xsl:template>

<xsl:template name="buildAnalyticsTable">       
    <!-- Age -->
    "<xsl:value-of select="$ageFieldName"/>" : {
    <xsl:apply-templates mode="buildAnalyticsTableRangeLevel" select="//detail/record[generate-id()=generate-id(key($ageFieldName, field[@name=$ageFieldName]))]">
        <xsl:with-param name="keyName" select="$ageFieldName"/>
        <xsl:with-param name="countField" select="'NUMOFCOUNTAGE'"/>     
        <xsl:with-param name="label" select="'Age Range'" />
        <xsl:with-param name="isGender" select="'false'" />
    </xsl:apply-templates>
    },

    <!-- Gender -->
    "<xsl:value-of select="$genderFieldName"/>" : {
    <xsl:apply-templates mode="buildAnalyticsTableRangeLevel" select="//detail/record[generate-id()=generate-id(key($genderFieldName, field[@name=$genderFieldName]))]">
        <xsl:with-param name="keyName" select="$genderFieldName"/>
        <xsl:with-param name="countField" select="'NUMOFGENDERCOUNT'"/>  
        <xsl:with-param name="label" select="'Gender'" />
        <xsl:with-param name="isGender" select="'true'" />
    </xsl:apply-templates>
    },

    <!-- Race -->
    "<xsl:value-of select="$raceFieldName"/>" : {
    <xsl:apply-templates mode="buildAnalyticsTableRangeLevel" select="//detail/record[generate-id()=generate-id(key($raceFieldName, field[@name=$raceFieldName]))]">
        <xsl:with-param name="keyName" select="$raceFieldName"/>
        <xsl:with-param name="countField" select="'NUMOFRACE'"/>     
        <xsl:with-param name="label" select="'Race'" />
        <xsl:with-param name="isGender" select="'true'" />
    </xsl:apply-templates>
    }

</xsl:template>

<xsl:template match="detail/record" mode="buildAnalyticsTableRangeLevel">
    <xsl:param name="keyName" />
    <xsl:param name="countField" /> 
    <xsl:param name="label" />
    <xsl:param name="isGender" />
    <xsl:variable name="value" >
        <xsl:call-template name="testForUnknown">
            <xsl:with-param name="name" select="field[@name=$keyName]"/>
        </xsl:call-template>
    </xsl:variable>
    <xsl:variable name="name">
        <xsl:call-template name="testForGender">
            <xsl:with-param name="isGender" select="$isGender"/>
            <xsl:with-param name="name" select="$value"/>
        </xsl:call-template>
    </xsl:variable>

    "<xsl:value-of select="$value"/>" : {       
    "analyticsLabel" : "<xsl:value-of select="$label"/>",
    "analyticsName" : "<xsl:value-of select="$name"/>",
    <xsl:apply-templates mode="buildAnalyticsTableCountLevel" select="key($keyName, field[@name=$keyName])[generate-id()=generate-id(key(concat($keyName, '_merge'), concat(field[@name=$keyName],'|', field[@name=$ouIdFieldName])))]">
        <xsl:with-param name="countField" select="$countField"/>
    </xsl:apply-templates>
    },          
</xsl:template>

<xsl:template match="detail/record" mode="buildAnalyticsTableCountLevel">
    <xsl:param name="countField" />
    "<xsl:value-of select="field[@name=$ouIdFieldName]"/>" : {
    "analyticsOUname" : "<xsl:value-of select="field[@name=$ouNameFieldName]"/>",
    "analyticsValue" : "<xsl:value-of select="field[@name=$countField]"/>"
    },
</xsl:template>    

<xsl:template name="testForUnknown">
    <xsl:param name="name" /> 
    <xsl:choose>        
        <xsl:when test="string-length($name) = 0">
            <xsl:value-of select="'Unknown'"/>
        </xsl:when>
        <xsl:otherwise>
            <xsl:value-of select="$name" />
        </xsl:otherwise>
    </xsl:choose>
</xsl:template>

<xsl:template name="testForGender">
    <xsl:param name="isGender" />
    <xsl:param name="name" /> 
    <xsl:choose>
        <xsl:when test="$isGender = 'true' and $name = 1">
            <xsl:value-of select="'male'" />            
        </xsl:when> 
        <xsl:when test="$isGender = 'true' and $name = 2">
            <xsl:value-of select="'female'" />      
        </xsl:when>
        <xsl:otherwise>
            <xsl:value-of select="$name" />
        </xsl:otherwise>
    </xsl:choose>
</xsl:template>

Here is the output of my transformation

    var analyticsMap = {        

    "AGERANGEID" : {


    "30-39" : {     
    "analyticsLabel" : "Age Range",
    "analyticsName" : "30-39",

    "00001001" : {
    "analyticsOUname" : "Human Resources",
    "analyticsValue" : "1"
    },

    },          


    "&gt;=70" : {       
    "analyticsLabel" : "Age Range",
    "analyticsName" : "&gt;=70",

    "00001001" : {
    "analyticsOUname" : "Human Resources",
    "analyticsValue" : "5"
    },

    "50000013" : {
    "analyticsOUname" : "IT computer center (D)",
    "analyticsValue" : "5"
    },

    },          


    "40-49" : {     
    "analyticsLabel" : "Age Range",
    "analyticsName" : "40-49",

    "50000013" : {
    "analyticsOUname" : "IT computer center (D)",
    "analyticsValue" : "1"
    },

    },          


    "50-59" : {     
    "analyticsLabel" : "Age Range",
    "analyticsName" : "50-59",

    "50000013" : {
    "analyticsOUname" : "IT computer center (D)",
    "analyticsValue" : "2"
    },

    },          

    },


    "GENDER" : {


    "2" : {     
    "analyticsLabel" : "Gender",
    "analyticsName" : "female",

    "00001001" : {
    "analyticsOUname" : "Human Resources",
    "analyticsValue" : "5"
    },

    "50000013" : {
    "analyticsOUname" : "IT computer center (D)",
    "analyticsValue" : "4"
    },

    },          


    "1" : {     
    "analyticsLabel" : "Gender",
    "analyticsName" : "male",

    "00001001" : {
    "analyticsOUname" : "Human Resources",
    "analyticsValue" : "7"
    },

    "50000147" : {
    "analyticsOUname" : "Personnel Administration (D)",
    "analyticsValue" : "3"
    },

    "50000013" : {
    "analyticsOUname" : "IT computer center (D)",
    "analyticsValue" : "4"
    },

    },          

    },


    "RACENAME" : {


    "Unknown" : {       
    "analyticsLabel" : "Race",
    "analyticsName" : "Unknown",

    },          


    "Asian" : {     
    "analyticsLabel" : "Race",
    "analyticsName" : "Asian",

    "00001001" : {
    "analyticsOUname" : "Human Resources",
    "analyticsValue" : "1"
    },

    },          


    "American Indian" : {       
    "analyticsLabel" : "Race",
    "analyticsName" : "American Indian",

    "00001001" : {
    "analyticsOUname" : "Human Resources",
    "analyticsValue" : "1"
    },

    },          

    }

};

As you can see, in the Race->Unknown section, it doesn’t complete it by applying the template mode “buildAnalyticsTableCountLevel” so I never get the ORGUNITID information which is very important in what I am doing.

I unfortunately cannot edit the xml coming in as this is a part of a much bigger framework used in various projects and I cannot change it. So I have to work with what I get.

I tried using the string() method in xsl:key but that makes everything worse. Any tips or help is appreciated. Thanks in advance!

  • 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-11T07:43:33+00:00Added an answer on June 11, 2026 at 7:43 am

    Change the start of the stylesheet like this:

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
     xmlns:my="my:my">
     <xsl:output method="text"/>
    
     <my:unknown>Unknown</my:unknown>
    

    and change one of the key definitions to:

     <xsl:key name="RACENAME_merge" match="detail/record" 
      use="concat((field[@name='RACENAME']
                  |document('')/*/my:unknown[not(field[@name='RACENAME'])]),
                  '|', field[@name='ORGUNITID'])"  />
    

    Finally, change one of the xsl:apply-templaes to this:

    <xsl:apply-templates mode="buildAnalyticsTableCountLevel"
    select="key($keyName, field[@name=$keyName])
              [generate-id()=generate-id(key(concat($keyName, '_merge'),
              concat((field[@name=$keyName]
                     |document('')/*/my:unknown[not(current()/field[@name='RACENAME'])]),
                     '|', field[@name=$ouIdFieldName])))]">
        <xsl:with-param name="countField" select="$countField"/>
    </xsl:apply-templates>
    

    The complete code after these changes becomes:

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
     xmlns:my="my:my">
     <xsl:output method="text"/>
    
     <my:unknown>Unknown</my:unknown>
    
     <!-- Start external variables -->
     <!-- Field names -->
     <xsl:variable name="ageFieldName" select="'AGERANGEID'" />
     <xsl:variable name="genderFieldName" select="'GENDER'" />
     <xsl:variable name="raceFieldName" select="'RACENAME'" />
     <xsl:variable name="ouIdFieldName" select="'ORGUNITID'" />
     <xsl:variable name="ouNameFieldName" select="'ORGUNITNAME'" />
    
     <!-- Keys -->
     <xsl:key use="field[@name='AGERANGEID']" name="AGERANGEID" match="detail/record" />
     <xsl:key use="concat(field[@name='AGERANGEID'],'|', field[@name='ORGUNITID'])" name="AGERANGEID_merge" match="detail/record" />
     <xsl:key use="field[@name='GENDER']" name="GENDER" match="detail/record" />
     <xsl:key use="concat(field[@name='GENDER'],'|', field[@name='ORGUNITID'])" name="GENDER_merge" match="detail/record" />
     <xsl:key use="field[@name='RACENAME']" name="RACENAME" match="detail/record" />
     <xsl:key use="concat((field[@name='RACENAME']
                         |document('')/*/my:unknown[not(current()/field[@name='RACENAME'])]),
                         '|', field[@name='ORGUNITID'])"
      name="RACENAME_merge" match="detail/record" />
    
     <xsl:key use="field[@name='ORGUNITID']" name="ORGUNITID" match="detail/record" />
    
    
     <xsl:template match="/">
        var analyticsMap = {<xsl:call-template name="buildAnalyticsTable" />};
     </xsl:template>
    
     <xsl:template name="buildAnalyticsTable">
        <!-- Age -->
        "<xsl:value-of select="$ageFieldName"/>" : {
        <xsl:apply-templates mode="buildAnalyticsTableRangeLevel" select="//detail/record[generate-id()=generate-id(key($ageFieldName, field[@name=$ageFieldName]))]">
            <xsl:with-param name="keyName" select="$ageFieldName"/>
            <xsl:with-param name="countField" select="'NUMOFCOUNTAGE'"/>
            <xsl:with-param name="label" select="'Age Range'" />
            <xsl:with-param name="isGender" select="'false'" />
        </xsl:apply-templates>
        },
    
        <!-- Gender -->
        "<xsl:value-of select="$genderFieldName"/>" : {
        <xsl:apply-templates mode="buildAnalyticsTableRangeLevel" select="//detail/record[generate-id()=generate-id(key($genderFieldName, field[@name=$genderFieldName]))]">
            <xsl:with-param name="keyName" select="$genderFieldName"/>
            <xsl:with-param name="countField" select="'NUMOFGENDERCOUNT'"/>
            <xsl:with-param name="label" select="'Gender'" />
            <xsl:with-param name="isGender" select="'true'" />
        </xsl:apply-templates>
        },
    
        <!-- Race -->
        "<xsl:value-of select="$raceFieldName"/>" : {
        <xsl:apply-templates mode="buildAnalyticsTableRangeLevel" select="//detail/record[generate-id()=generate-id(key($raceFieldName, field[@name=$raceFieldName]))]">
            <xsl:with-param name="keyName" select="$raceFieldName"/>
            <xsl:with-param name="countField" select="'NUMOFRACE'"/>
            <xsl:with-param name="label" select="'Race'" />
            <xsl:with-param name="isGender" select="'true'" />
        </xsl:apply-templates>
        }
    
     </xsl:template>
    
     <xsl:template match="detail/record" mode="buildAnalyticsTableRangeLevel">
        <xsl:param name="keyName" />
        <xsl:param name="countField" />
        <xsl:param name="label" />
        <xsl:param name="isGender" />
        <xsl:variable name="value" >
            <xsl:call-template name="testForUnknown">
                <xsl:with-param name="name" select="field[@name=$keyName]"/>
            </xsl:call-template>
        </xsl:variable>
        <xsl:variable name="name">
            <xsl:call-template name="testForGender">
                <xsl:with-param name="isGender" select="$isGender"/>
                <xsl:with-param name="name" select="$value"/>
            </xsl:call-template>
        </xsl:variable>
    
        "<xsl:value-of select="$value"/>" : {
        "analyticsLabel" : "<xsl:value-of select="$label"/>",
        "analyticsName" : "<xsl:value-of select="$name"/>",
        <xsl:apply-templates mode="buildAnalyticsTableCountLevel"
        select="key($keyName, field[@name=$keyName])
                  [generate-id()=generate-id(key(concat($keyName, '_merge'),
                  concat((field[@name=$keyName]
                         |document('')/*/my:unknown[not(current()/field[@name='RACENAME'])]),
                         '|', field[@name=$ouIdFieldName])))]">
            <xsl:with-param name="countField" select="$countField"/>
        </xsl:apply-templates>
        },
     </xsl:template>
    
     <xsl:template match="detail/record" mode="buildAnalyticsTableCountLevel">
        <xsl:param name="countField" />
        "<xsl:value-of select="field[@name=$ouIdFieldName]"/>" : {
        "analyticsOUname" : "<xsl:value-of select="field[@name=$ouNameFieldName]"/>",
        "analyticsValue" : "<xsl:value-of select="field[@name=$countField]"/>"
        },
     </xsl:template>
    
     <xsl:template name="testForUnknown">
        <xsl:param name="name" />
        <xsl:choose>
            <xsl:when test="string-length($name) = 0">
                <xsl:value-of select="'Unknown'"/>
            </xsl:when>
            <xsl:otherwise>
                <xsl:value-of select="$name" />
            </xsl:otherwise>
        </xsl:choose>
     </xsl:template>
    
     <xsl:template name="testForGender">
        <xsl:param name="isGender" />
        <xsl:param name="name" />
        <xsl:choose>
            <xsl:when test="$isGender = 'true' and $name = 1">
                <xsl:value-of select="'male'" />
            </xsl:when>
            <xsl:when test="$isGender = 'true' and $name = 2">
                <xsl:value-of select="'female'" />
            </xsl:when>
            <xsl:otherwise>
                <xsl:value-of select="$name" />
            </xsl:otherwise>
        </xsl:choose>
     </xsl:template>
    </xsl:stylesheet>
    

    and when this transformation is applied on the provided XML document:

    <cds>
        <sections>
            <section name="myteam_CurrentAgeCompleteSection" link="false">
                <detail name="">
                    <record>
                        <field name="AGERANGEID">30-39</field>
                        <field name="NUMOFCOUNTAGE">1</field>
                        <field name="ORGUNITID">00001001</field>
                        <field name="PARENTORGUNITID">00000100</field>
                        <field name="ORGUNITNAME">Human Resources</field>
                    </record>
                    <record>
                        <field name="AGERANGEID">&gt;=70</field>
                        <field name="NUMOFCOUNTAGE">5</field>
                        <field name="ORGUNITID">00001001</field>
                        <field name="PARENTORGUNITID">00000100</field>
                        <field name="ORGUNITNAME">Human Resources</field>
                    </record>
                </detail>
            </section>
            <section name="myteam_CurrentGenderCompleteSection" link="false">
                <detail name="">
                    <record>
                        <field name="PARENTORGUNITID">00000100</field>
                        <field name="ORGUNITID">00001001</field>
                        <field name="ORGUNITNAME">Human Resources</field>
                        <field name="NUMOFGENDERCOUNT">5</field>
                        <field name="GENDER">2</field>
                    </record>
                    <record>
                        <field name="PARENTORGUNITID">00000100</field>
                        <field name="ORGUNITID">00001001</field>
                        <field name="ORGUNITNAME">Human Resources</field>
                        <field name="NUMOFGENDERCOUNT">7</field>
                        <field name="GENDER">1</field>
                    </record>
                </detail>
            </section>
            <section name="myteam_CurrentRaceCompleteSection" link="false">
                <detail name="">
                    <record>
                        <field name="ORGUNITNAME">Human Resources</field>
                        <field name="PARENTORGUNITID">00000100</field>
                        <field name="ORGUNITID">00001001</field>
                        <field name="NUMOFRACE">10.0</field>
                        <field name="RACENAME" />
                    </record>
                    <record>
                        <field name="ORGUNITNAME">Human Resources</field>
                        <field name="PARENTORGUNITID">00000100</field>
                        <field name="ORGUNITID">00001001</field>
                        <field name="NUMOFRACE">1</field>
                        <field name="RACENAME">Asian</field>
                    </record>
                    <record>
                        <field name="ORGUNITNAME">Human Resources</field>
                        <field name="PARENTORGUNITID">00000100</field>
                        <field name="ORGUNITID">00001001</field>
                        <field name="NUMOFRACE">1</field>
                        <field name="RACENAME">American Indian</field>
                    </record>
                </detail>
            </section>
            <section name="myteam_ChildAgeColumnSection" link="false">
                <detail name="">
                    <record>
                        <field name="AGERANGEID">40-49</field>
                        <field name="NUMOFCOUNTAGE">1</field>
                        <field name="ORGUNITID">50000013</field>
                        <field name="PARENTORGUNITID">00001001</field>
                        <field name="ORGUNITNAME">IT computer center (D)</field>
                    </record>
                    <record>
                        <field name="AGERANGEID">50-59</field>
                        <field name="NUMOFCOUNTAGE">2</field>
                        <field name="ORGUNITID">50000013</field>
                        <field name="PARENTORGUNITID">00001001</field>
                        <field name="ORGUNITNAME">IT computer center (D)</field>
                    </record>
                    <record>
                        <field name="AGERANGEID">&gt;=70</field>
                        <field name="NUMOFCOUNTAGE">5</field>
                        <field name="ORGUNITID">50000013</field>
                        <field name="PARENTORGUNITID">00001001</field>
                        <field name="ORGUNITNAME">IT computer center (D)</field>
                    </record>
                </detail>
            </section>
            <section name="myteam_ChildGenderColumnSection" link="false">
                <detail name="">
                    <record>
                        <field name="PARENTORGUNITID">00001001</field>
                        <field name="ORGUNITID">50000013</field>
                        <field name="ORGUNITNAME">IT computer center (D)</field>
                        <field name="NUMOFGENDERCOUNT">4</field>
                        <field name="GENDER">2</field>
                    </record>
                    <record>
                        <field name="PARENTORGUNITID">00001001</field>
                        <field name="ORGUNITID">50000147</field>
                        <field name="ORGUNITNAME">Personnel Administration (D)</field>
                        <field name="NUMOFGENDERCOUNT">3</field>
                        <field name="GENDER">1</field>
                    </record>
                    <record>
                        <field name="PARENTORGUNITID">00001001</field>
                        <field name="ORGUNITID">50000013</field>
                        <field name="ORGUNITNAME">IT computer center (D)</field>
                        <field name="NUMOFGENDERCOUNT">4</field>
                        <field name="GENDER">1</field>
                    </record>
                </detail>
            </section>
            <section name="myteam_ChildGenderColumnSection" link="false">
                <detail name="">
                    <record>
                        <field name="PARENTORGUNITID">00001001</field>
                        <field name="ORGUNITID">50000013</field>
                        <field name="ORGUNITNAME">IT computer center (D)</field>
                        <field name="NUMOFGENDERCOUNT">4</field>
                        <field name="GENDER">2</field>
                    </record>
                    <record>
                        <field name="PARENTORGUNITID">00001001</field>
                        <field name="ORGUNITID">50000147</field>
                        <field name="ORGUNITNAME">Personnel Administration (D)</field>
                        <field name="NUMOFGENDERCOUNT">3</field>
                        <field name="GENDER">1</field>
                    </record>
                    <record>
                        <field name="PARENTORGUNITID">00001001</field>
                        <field name="ORGUNITID">50000013</field>
                        <field name="ORGUNITNAME">IT computer center (D)</field>
                        <field name="NUMOFGENDERCOUNT">4</field>
                        <field name="GENDER">1</field>
                    </record>
                </detail>
            </section>
            <section name="myteam_ChildGenderColumnSection" link="false">
                <detail name="">
                    <record>
                        <field name="PARENTORGUNITID">00001001</field>
                        <field name="ORGUNITID">50000013</field>
                        <field name="ORGUNITNAME">IT computer center (D)</field>
                        <field name="NUMOFGENDERCOUNT">4</field>
                        <field name="GENDER">2</field>
                    </record>
                    <record>
                        <field name="PARENTORGUNITID">00001001</field>
                        <field name="ORGUNITID">50000147</field>
                        <field name="ORGUNITNAME">Personnel Administration (D)</field>
                        <field name="NUMOFGENDERCOUNT">3</field>
                        <field name="GENDER">1</field>
                    </record>
                </detail>
            </section>
        </sections>
    </cds>
    

    the wanted, correct result is produced:

        var analyticsMap = {
    
        "AGERANGEID" : {
    
    
        "30-39" : {
        "analyticsLabel" : "Age Range",
        "analyticsName" : "30-39",
    
        "00001001" : {
        "analyticsOUname" : "Human Resources",
        "analyticsValue" : "1"
        },
    
        },
    
    
        ">=70" : {
        "analyticsLabel" : "Age Range",
        "analyticsName" : ">=70",
    
        "00001001" : {
        "analyticsOUname" : "Human Resources",
        "analyticsValue" : "5"
        },
    
        "50000013" : {
        "analyticsOUname" : "IT computer center (D)",
        "analyticsValue" : "5"
        },
    
        },
    
    
        "40-49" : {
        "analyticsLabel" : "Age Range",
        "analyticsName" : "40-49",
    
        "50000013" : {
        "analyticsOUname" : "IT computer center (D)",
        "analyticsValue" : "1"
        },
    
        },
    
    
        "50-59" : {
        "analyticsLabel" : "Age Range",
        "analyticsName" : "50-59",
    
        "50000013" : {
        "analyticsOUname" : "IT computer center (D)",
        "analyticsValue" : "2"
        },
    
        },
    
        },
    
    
        "GENDER" : {
    
    
        "2" : {
        "analyticsLabel" : "Gender",
        "analyticsName" : "female",
    
        "00001001" : {
        "analyticsOUname" : "Human Resources",
        "analyticsValue" : "5"
        },
    
        "50000013" : {
        "analyticsOUname" : "IT computer center (D)",
        "analyticsValue" : "4"
        },
    
        },
    
    
        "1" : {
        "analyticsLabel" : "Gender",
        "analyticsName" : "male",
    
        "00001001" : {
        "analyticsOUname" : "Human Resources",
        "analyticsValue" : "7"
        },
    
        "50000147" : {
        "analyticsOUname" : "Personnel Administration (D)",
        "analyticsValue" : "3"
        },
    
        "50000013" : {
        "analyticsOUname" : "IT computer center (D)",
        "analyticsValue" : "4"
        },
    
        },
    
        },
    
    
        "RACENAME" : {
    
    
        "Unknown" : {
        "analyticsLabel" : "Race",
        "analyticsName" : "Unknown",
    
        "00001001" : {
        "analyticsOUname" : "Human Resources",
        "analyticsValue" : "10.0"
        },
    
        },
    
    
        "Asian" : {
        "analyticsLabel" : "Race",
        "analyticsName" : "Asian",
    
        "00001001" : {
        "analyticsOUname" : "Human Resources",
        "analyticsValue" : "1"
        },
    
        },
    
    
        "American Indian" : {
        "analyticsLabel" : "Race",
        "analyticsName" : "American Indian",
    
        "00001001" : {
        "analyticsOUname" : "Human Resources",
        "analyticsValue" : "1"
        },
    
        },
    
        }
    
     };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is my first time posting a question here, it has been a valuable
This is my first time posting. I've been working on a web scraper to
this is my first time posting here, I have a question which I have
That's my first time posting on stackoverflow. I've been finding usefull answers on this
this is my first time posting on here and have read alot of helpful
First time posting here, will try to be succinct. This is a classic 'can't
First and foremost, apologies for any cross-posting. Hope I'm not repeating an issue here,
this is my first time posting here, but I didn't know where else to
So this is my first time posting here but I'm more or less stumped.
This is my first time posting here, but I've found a lot of answers

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.