3

这是我第一次在这里发帖,所以对于篇幅和任何格式问题或缺乏信息,我提前道歉。我已经解决这个问题几天了,我已经广泛研究了我的问题,但还没有找到解决方案,所以我希望这里有人可以帮助我。这是一个与 xslt 相关的问题,几个月前我才开始在 xslt 中编码,所以我没有那么有经验。

基本上,我有一个输入 XML,其中可能包含重复记录和空标签,我需要将它们重新组织成一个 javascript 关联数组,以便能够在客户端有效地操作和显示这些值。

我的问题是:即使使用的字段标签为空,是否有办法进行多级分组。如果没有,有没有办法通过用关键字替换空标签然后应用我的模板的其余部分来编辑 xsl 中的 xml?

要了解我的问题,这里有详细信息。这是我的输入 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>

上网查了一下,发现处理多级分组的最好方法是使用xsl:key和generate-id()。效果很好,数据完全符合我的要求,所以我的 xsl 流程是正确的。但不幸的是,如果 xsl:key 中使用的字段是一个空标签,当我使用 concat() 进入多级分组时,它会失败。

<!-- 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>

这是我的转换的输出

    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"
    },

    },          

    }

};

正如你所看到的,在 Race->Unknown 部分,它并没有通过应用模板模式“buildAnalyticsTableCountLevel”来完成它,所以我从来没有得到 ORGUNITID 信息,这对我正在做的事情非常重要。

不幸的是,我无法编辑传入的 xml,因为这是在各种项目中使用的更大框架的一部分,我无法更改它。所以我必须用我得到的东西工作。

我尝试在 xsl:key 中使用 string() 方法,但这让一切变得更糟。任何提示或帮助表示赞赏。提前致谢!

4

1 回答 1

1

像这样更改样式表的开头

<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>

并将其中一个key定义更改为:

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

最后,将其中一个更改xsl:apply-templaes为:

<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: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>

当此转换应用于提供的 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>

产生了想要的正确结果

    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"
    },

    },

    }

 };
于 2012-09-14T03:32:08.883 回答