tia_kamakshi
asked on
How to do Grouping on the basis of attribute as well as removing the childs nodes from current xml.
Hi Experts,
I have got below attached full xml as a output.
NavigationOutput.xml
Here is the part of above attached XML, to express the logic to be implemented.
In above part XML, you can see that I have got an attribute with name "GroupCode", Now I want to group it as well as I want to remove the child nodes ("100. Login" and "110. Logout") from top xml and will be added in the grouped part below, however the parent node will exist on the top xml. Below will be output after being transformed using xslt 1.0.
Below is XSLT which I am trying to write but not able to get the actual required result.
The output from above XSLT is as below:
My XSLT is not able to get value here <node GroupTitle="" GroupCode="" GroupID="">
as well as I am not able to remove the Child grouped Items from the top XML.
Please suggest!!
I have got below attached full xml as a output.
NavigationOutput.xml
Here is the part of above attached XML, to express the logic to be implemented.
<node title="040. Skywards" id="tcm:233-38448-4" url="/Skywards/skywards.aspx" indexpage="tcm:233-192262-64" compTitle="Skywards" imageSrcOn="/Preview/companyglobal/english/images/skywards_highlight_tcm233-343464.gif" imageSrcOff="/Preview/companyglobal/english/images/skywards_tcm233-343463.gif" imageSrcSelected="/Preview/companyglobal/english/images/skywards_active_tcm233-343465.gif" imageSrcSelectedOn="/Preview/companyglobal/english/images/skywards_highlight_tcm233-343464.gif" accessKey="S" GroupTitle="Skywards and Business Rewards" GroupCode="SB" GroupID="tcm:233-358296">
<node title="010. Membership Tiers" id="tcm:233-38882-4" url="/Skywards/membership_tiers/membership_tiers.aspx" indexpage="tcm:233-194317-64" compTitle="Membership Tiers"/>
<node title="020. Earning Miles" id="tcm:233-38883-4" url="/Skywards/earning_miles/earning_miles.aspx" indexpage="tcm:233-194318-64" compTitle="Earning Skywards Miles"/>
<node title="030. Travel Rewards" id="tcm:233-38884-4" url="/Skywards/travel_rewards/travel_rewards.aspx" indexpage="tcm:233-194320-64" compTitle="Travel Rewards"/>
<node title="040. Journey Management Tools" id="tcm:233-38885-4" url="/Skywards/journey_management_tools/journey_management.aspx" indexpage="tcm:233-194322-64" compTitle="Journey Management "/>
<node title="050. Personal Travel Coordinator" id="tcm:233-38886-4" url="/Skywards/personal_travel_coordinator/personal_travel_coordinator.aspx" indexpage="tcm:233-194324-64" compTitle="Personal Travel Coordinator"/>
<node title="060. Skysurfers" id="tcm:233-38887-4" url="/Skywards/skysurfers/skysurfers.aspx" indexpage="tcm:233-194326-64" compTitle="Skysurfers"/>
<node title="070. Become a Skywards member" id="tcm:233-56534-4" url="http://www.skywards.com/join_now_personal.aspx" indexpage="tcm:233-305043-64" linktype="external" compTitle="Become a Skywards member"/>
<node title="080. The company High Street" id="tcm:233-59871-4" url="/Skywards/the_company_high_street/the_company_high_street.aspx" indexpage="tcm:233-346057-64" compTitle="The company High Street"/>
<node title="090. Log In" id="tcm:233-92637-4" url="https://www.skywards.com/index.aspx" indexpage="tcm:233-636665-64" linktype="external" compTitle="Log In"/>
<node title="100. Login" id="tcm:233-93287-4" url="/Skywards/skywardLogin/" GroupTitle="Skywards and Business Rewards" GroupCode="SB" GroupID="tcm:233-358296"/>
<node title="110. Logout" id="tcm:233-93288-4" url="/Skywards/skywardLogout/" GroupTitle="Skywards and Business Rewards" GroupCode="SB" GroupID="tcm:233-358296"/>
</node>
In above part XML, you can see that I have got an attribute with name "GroupCode", Now I want to group it as well as I want to remove the child nodes ("100. Login" and "110. Logout") from top xml and will be added in the grouped part below, however the parent node will exist on the top xml. Below will be output after being transformed using xslt 1.0.
<node title="040. Skywards" id="tcm:233-38448-4" url="/Skywards/skywards.aspx" indexpage="tcm:233-192262-64" compTitle="Skywards" imageSrcOn="/Preview/companyglobal/english/images/skywards_highlight_tcm233-343464.gif" imageSrcOff="/Preview/companyglobal/english/images/skywards_tcm233-343463.gif" imageSrcSelected="/Preview/companyglobal/english/images/skywards_active_tcm233-343465.gif" imageSrcSelectedOn="/Preview/companyglobal/english/images/skywards_highlight_tcm233-343464.gif" accessKey="S" GroupTitle="Skywards and Business Rewards" GroupCode="SB" GroupID="tcm:233-358296">
<node title="010. Membership Tiers" id="tcm:233-38882-4" url="/Skywards/membership_tiers/membership_tiers.aspx" indexpage="tcm:233-194317-64" compTitle="Membership Tiers"/>
<node title="020. Earning Miles" id="tcm:233-38883-4" url="/Skywards/earning_miles/earning_miles.aspx" indexpage="tcm:233-194318-64" compTitle="Earning Skywards Miles"/>
<node title="030. Travel Rewards" id="tcm:233-38884-4" url="/Skywards/travel_rewards/travel_rewards.aspx" indexpage="tcm:233-194320-64" compTitle="Travel Rewards"/>
<node title="040. Journey Management Tools" id="tcm:233-38885-4" url="/Skywards/journey_management_tools/journey_management.aspx" indexpage="tcm:233-194322-64" compTitle="Journey Management "/>
<node title="050. Personal Travel Coordinator" id="tcm:233-38886-4" url="/Skywards/personal_travel_coordinator/personal_travel_coordinator.aspx" indexpage="tcm:233-194324-64" compTitle="Personal Travel Coordinator"/>
<node title="060. Skysurfers" id="tcm:233-38887-4" url="/Skywards/skysurfers/skysurfers.aspx" indexpage="tcm:233-194326-64" compTitle="Skysurfers"/>
<node title="070. Become a Skywards member" id="tcm:233-56534-4" url="http://www.skywards.com/join_now_personal.aspx" indexpage="tcm:233-305043-64" linktype="external" compTitle="Become a Skywards member"/>
<node title="080. The company High Street" id="tcm:233-59871-4" url="/Skywards/the_company_high_street/the_company_high_street.aspx" indexpage="tcm:233-346057-64" compTitle="The company High Street"/>
<node title="090. Log In" id="tcm:233-92637-4" url="https://www.skywards.com/index.aspx" indexpage="tcm:233-636665-64" linktype="external" compTitle="Log In"/>
</node>
<node GroupTitle="Skywards and Business Rewards" GroupCode="SB" GroupID="tcm:233-358296">
<nodes>
<node title="035. Business Rewards" id="tcm:233-58061-4" url="/business_rewards/business_rewards.aspx" indexpage="tcm:233-358352-64" compTitle="Business Rewards" imageSrcOn="/Preview/companyglobal/english/images/business_rewards_highlight_tcm233-324549.gif" imageSrcOff="/Preview/companyglobal/english/images/business_rewards_tcm233-324548.gif" imageSrcSelected="/Preview/companyglobal/english/images/business_rewards_active_tcm233-324551.gif" imageSrcSelectedOn="/Preview/companyglobal/english/images/business_rewards_highlight_tcm233-324549.gif" authentication="sme-guest" GroupTitle="Skywards and Business Rewards" GroupCode="SB" GroupID="tcm:233-358296"/>
<node title="040. Skywards" id="tcm:233-38448-4" url="/Skywards/skywards.aspx" indexpage="tcm:233-192262-64" compTitle="Skywards" imageSrcOn="/Preview/companyglobal/english/images/skywards_highlight_tcm233-343464.gif" imageSrcOff="/Preview/companyglobal/english/images/skywards_tcm233-343463.gif" imageSrcSelected="/Preview/companyglobal/english/images/skywards_active_tcm233-343465.gif" imageSrcSelectedOn="/Preview/companyglobal/english/images/skywards_highlight_tcm233-343464.gif" accessKey="S" GroupTitle="Skywards and Business Rewards" GroupCode="SB" GroupID="tcm:233-358296">
<node title="100. Login" id="tcm:233-93287-4" url="/Skywards/skywardLogin/" GroupTitle="Skywards and Business Rewards" GroupCode="SB" GroupID="tcm:233-358296"/>
<node title="110. Logout" id="tcm:233-93288-4" url="/Skywards/skywardLogout/" GroupTitle="Skywards and Business Rewards" GroupCode="SB" GroupID="tcm:233-358296"/>
</node>
</nodes>
</node>
Below is XSLT which I am trying to write but not able to get the actual required result.
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:strip-space elements="*"/>
<xsl:output indent="yes"/>
<xsl:template match="*">
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:apply-templates select="node()"/>
<xsl:if test="self::navigation">
<node GroupTitle="{@GroupTitle}" GroupCode="{@GroupCode}" GroupID="{@GroupID}">
<nodes>
<xsl:apply-templates select="node()" mode="group"></xsl:apply-templates>
</nodes>
</node>
</xsl:if>
</xsl:copy>
</xsl:template>
<xsl:template match="node" mode="group">
<xsl:choose>
<xsl:when test="@GroupCode !=''">
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:apply-templates select="node()" mode="group"/>
</xsl:copy>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="node()" mode="group"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="*" mode="group"/>
</xsl:stylesheet>
The output from above XSLT is as below:
<node title="040. Skywards" id="tcm:233-38448-4" url="/Skywards/skywards.aspx" indexpage="tcm:233-192262-64" compTitle="Skywards" imageSrcOn="/Preview/companyglobal/english/images/skywards_highlight_tcm233-343464.gif" imageSrcOff="/Preview/companyglobal/english/images/skywards_tcm233-343463.gif" imageSrcSelected="/Preview/companyglobal/english/images/skywards_active_tcm233-343465.gif" imageSrcSelectedOn="/Preview/companyglobal/english/images/skywards_highlight_tcm233-343464.gif" accessKey="S" GroupTitle="Skywards and Business Rewards" GroupCode="SB" GroupID="tcm:233-358296">
<node title="010. Membership Tiers" id="tcm:233-38882-4" url="/Skywards/membership_tiers/membership_tiers.aspx" indexpage="tcm:233-194317-64" compTitle="Membership Tiers"/>
<node title="020. Earning Miles" id="tcm:233-38883-4" url="/Skywards/earning_miles/earning_miles.aspx" indexpage="tcm:233-194318-64" compTitle="Earning Skywards Miles"/>
<node title="030. Travel Rewards" id="tcm:233-38884-4" url="/Skywards/travel_rewards/travel_rewards.aspx" indexpage="tcm:233-194320-64" compTitle="Travel Rewards"/>
<node title="040. Journey Management Tools" id="tcm:233-38885-4" url="/Skywards/journey_management_tools/journey_management.aspx" indexpage="tcm:233-194322-64" compTitle="Journey Management "/>
<node title="050. Personal Travel Coordinator" id="tcm:233-38886-4" url="/Skywards/personal_travel_coordinator/personal_travel_coordinator.aspx" indexpage="tcm:233-194324-64" compTitle="Personal Travel Coordinator"/>
<node title="060. Skysurfers" id="tcm:233-38887-4" url="/Skywards/skysurfers/skysurfers.aspx" indexpage="tcm:233-194326-64" compTitle="Skysurfers"/>
<node title="070. Become a Skywards member" id="tcm:233-56534-4" url="http://www.skywards.com/join_now_personal.aspx" indexpage="tcm:233-305043-64" linktype="external" compTitle="Become a Skywards member"/>
<node title="080. The company High Street" id="tcm:233-59871-4" url="/Skywards/the_company_high_street/the_company_high_street.aspx" indexpage="tcm:233-346057-64" compTitle="The company High Street"/>
<node title="090. Log In" id="tcm:233-92637-4" url="https://www.skywards.com/index.aspx" indexpage="tcm:233-636665-64" linktype="external" compTitle="Log In"/>
<node title="100. Login" id="tcm:233-93287-4" url="/Skywards/skywardLogin/" GroupTitle="Skywards and Business Rewards" GroupCode="SB" GroupID="tcm:233-358296"/>
<node title="110. Logout" id="tcm:233-93288-4" url="/Skywards/skywardLogout/" GroupTitle="Skywards and Business Rewards" GroupCode="SB" GroupID="tcm:233-358296"/>
</node>
<node GroupTitle="" GroupCode="" GroupID="">
<nodes>
<node title="035. Business Rewards" id="tcm:233-58061-4" url="/business_rewards/business_rewards.aspx" indexpage="tcm:233-358352-64" compTitle="Business Rewards" imageSrcOn="/Preview/companyglobal/english/images/business_rewards_highlight_tcm233-324549.gif" imageSrcOff="/Preview/companyglobal/english/images/business_rewards_tcm233-324548.gif" imageSrcSelected="/Preview/companyglobal/english/images/business_rewards_active_tcm233-324551.gif" imageSrcSelectedOn="/Preview/companyglobal/english/images/business_rewards_highlight_tcm233-324549.gif" authentication="sme-guest" GroupTitle="Skywards and Business Rewards" GroupCode="SB" GroupID="tcm:233-358296"/>
<node title="040. Skywards" id="tcm:233-38448-4" url="/Skywards/skywards.aspx" indexpage="tcm:233-192262-64" compTitle="Skywards" imageSrcOn="/Preview/companyglobal/english/images/skywards_highlight_tcm233-343464.gif" imageSrcOff="/Preview/companyglobal/english/images/skywards_tcm233-343463.gif" imageSrcSelected="/Preview/companyglobal/english/images/skywards_active_tcm233-343465.gif" imageSrcSelectedOn="/Preview/companyglobal/english/images/skywards_highlight_tcm233-343464.gif" accessKey="S" GroupTitle="Skywards and Business Rewards" GroupCode="SB" GroupID="tcm:233-358296">
<node title="100. Login" id="tcm:233-93287-4" url="/Skywards/skywardLogin/" GroupTitle="Skywards and Business Rewards" GroupCode="SB" GroupID="tcm:233-358296"/>
<node title="110. Logout" id="tcm:233-93288-4" url="/Skywards/skywardLogout/" GroupTitle="Skywards and Business Rewards" GroupCode="SB" GroupID="tcm:233-358296"/>
</node>
</nodes>
</node>
My XSLT is not able to get value here <node GroupTitle="" GroupCode="" GroupID="">
as well as I am not able to remove the Child grouped Items from the top XML.
Please suggest!!
ASKER
Hi Gertone,
I am clear what you are trying to say here:
I believe that teh discrimator is that you want to remove from the common processing,
those elements that are in a group and have no children that are not in a group.
Can you please add your logic in my XSLT or give me full XSLT so that I can test it and confirm.
Please suggest!!
Thanks
I am clear what you are trying to say here:
I believe that teh discrimator is that you want to remove from the common processing,
those elements that are in a group and have no children that are not in a group.
Can you please add your logic in my XSLT or give me full XSLT so that I can test it and confirm.
Please suggest!!
Thanks
I did,
next to your templates you have to add the one template I sent you
<xsl:template match="*[normalize-space(@ GroupCode) and not(*[not(normalize-space( @GroupCode ))])]"/>
that is all there is to it
I think in order to know for sure, you need to send the full source XML, since I don't see a navigation, that is why the grouping doesn't work on this snippet alone
next to your templates you have to add the one template I sent you
<xsl:template match="*[normalize-space(@
that is all there is to it
I think in order to know for sure, you need to send the full source XML, since I don't see a navigation, that is why the grouping doesn't work on this snippet alone
ASKER
Hi Gertone if you see on top where I have asked the question, I have embed the full navigation, please let me know if you require it again.
in my xslt I have called three places the templates, where I need to put your template and also why I am not able to get values here in my xslt
<node GroupTitle="{@GroupTitle}" GroupCode="{@GroupCode}" GroupID="{@GroupID}">
above code is returning blank values to me.
Please suggest!!
in my xslt I have called three places the templates, where I need to put your template and also why I am not able to get values here in my xslt
<node GroupTitle="{@GroupTitle}"
above code is returning blank values to me.
Please suggest!!
ASKER
Ok I am able to get my required result by adding your template, but two problems still exists as I am still getting
You can see there is blank values in the top node. And second thing is that, how can I remove any attribute if that is not required while doing the grouping.
Thanks.
<node GroupTitle="" GroupCode="" GroupID="">
<nodes>
<node title="035. Business Rewards" id="tcm:233-58061-4" url="/business_rewards/business_rewards.aspx" indexpage="tcm:233-358352-64" compTitle="Business Rewards" imageSrcOn="/Preview/companyglobal/english/images/business_rewards_highlight_tcm233-324549.gif" imageSrcOff="/Preview/companyglobal/english/images/business_rewards_tcm233-324548.gif" imageSrcSelected="/Preview/companyglobal/english/images/business_rewards_active_tcm233-324551.gif" imageSrcSelectedOn="/Preview/companyglobal/english/images/business_rewards_highlight_tcm233-324549.gif" authentication="sme-guest" GroupTitle="Skywards and Business Rewards" GroupCode="SB" GroupID="tcm:233-358296"/>
<node title="040. Skywards" id="tcm:233-38448-4" url="/Skywards/skywards.aspx" indexpage="tcm:233-192262-64" compTitle="Skywards" imageSrcOn="/Preview/companyglobal/english/images/skywards_highlight_tcm233-343464.gif" imageSrcOff="/Preview/companyglobal/english/images/skywards_tcm233-343463.gif" imageSrcSelected="/Preview/companyglobal/english/images/skywards_active_tcm233-343465.gif" imageSrcSelectedOn="/Preview/companyglobal/english/images/skywards_highlight_tcm233-343464.gif" accessKey="S" GroupTitle="Skywards and Business Rewards" GroupCode="SB" GroupID="tcm:233-358296">
<node title="100. Login" id="tcm:233-93287-4" url="/Skywards/skywardLogin/" GroupTitle="Skywards and Business Rewards" GroupCode="SB" GroupID="tcm:233-358296"/>
<node title="110. Logout" id="tcm:233-93288-4" url="/Skywards/skywardLogout/" GroupTitle="Skywards and Business Rewards" GroupCode="SB" GroupID="tcm:233-358296"/>
</node>
</nodes>
</node>
You can see there is blank values in the top node. And second thing is that, how can I remove any attribute if that is not required while doing the grouping.
Thanks.
OK, I did not spot the full XML attached,
got it now
navigation has no such attributes, that is why you get empty values
You simply make one node for grouping at the end.
What is your grouping logic?
in other words, what do you want to appear in the group?
got it now
navigation has no such attributes, that is why you get empty values
You simply make one node for grouping at the end.
What is your grouping logic?
in other words, what do you want to appear in the group?
ASKER
Hi Gertone,
Above XSLT code I have only got with me and below is the output which I am looking and grouping will be on the basis of attribute @GroupCode. So my output will be as below:
but the problem is that I am getting blank <node GroupTitle="" GroupCode="" GroupID="">
And after this can you please give me logic, if I want to remove particular attribute while I am doing the grouping.
Above XSLT code I have only got with me and below is the output which I am looking and grouping will be on the basis of attribute @GroupCode. So my output will be as below:
<node GroupTitle="Skywards and Business Rewards" GroupCode="SB" GroupID="tcm:233-358296">
<nodes>
<node title="035. Business Rewards" id="tcm:233-58061-4" url="/business_rewards/business_rewards.aspx" indexpage="tcm:233-358352-64" compTitle="Business Rewards" imageSrcOn="/Preview/companyglobal/english/images/business_rewards_highlight_tcm233-324549.gif" imageSrcOff="/Preview/companyglobal/english/images/business_rewards_tcm233-324548.gif" imageSrcSelected="/Preview/companyglobal/english/images/business_rewards_active_tcm233-324551.gif" imageSrcSelectedOn="/Preview/companyglobal/english/images/business_rewards_highlight_tcm233-324549.gif" authentication="sme-guest" GroupTitle="Skywards and Business Rewards" GroupCode="SB" GroupID="tcm:233-358296">
<node title="046. Business Rewards Awards Calculator" id="tcm:233-88592-4" url="/SME.aspx&NavigateTo=MilesCalculator" linktype="ibe" compTitle="Business Rewards Awards Calculator" localTitle="Business Rewards Awards Calculator" GroupTitle="Skywards and Business Rewards" GroupCode="SB" GroupID="tcm:233-358296"/>
<node title="090. Travel Activity (User)" id="tcm:233-58080-4" url="/SME.aspx&NavigateTo=TravelActivityU" linktype="ibe" compTitle="Travel Activity" linksection="SME" authentication="sme-user" GroupTitle="Skywards and Business Rewards" GroupCode="SB" GroupID="tcm:233-358296"/>
</node>
<node title="040. Skywards" id="tcm:233-38448-4" url="/Skywards/skywards.aspx" indexpage="tcm:233-192262-64" compTitle="Skywards" imageSrcOn="/Preview/companyglobal/english/images/skywards_highlight_tcm233-343464.gif" imageSrcOff="/Preview/companyglobal/english/images/skywards_tcm233-343463.gif" imageSrcSelected="/Preview/companyglobal/english/images/skywards_active_tcm233-343465.gif" imageSrcSelectedOn="/Preview/companyglobal/english/images/skywards_highlight_tcm233-343464.gif" accessKey="S" GroupTitle="Skywards and Business Rewards" GroupCode="SB" GroupID="tcm:233-358296">
<node title="100. Login" id="tcm:233-93287-4" url="/Skywards/skywardLogin/" GroupTitle="Skywards and Business Rewards" GroupCode="SB" GroupID="tcm:233-358296"/>
<node title="110. Logout" id="tcm:233-93288-4" url="/Skywards/skywardLogout/" GroupTitle="Skywards and Business Rewards" GroupCode="SB" GroupID="tcm:233-358296"/>
</node>
</nodes>
</node>
but the problem is that I am getting blank <node GroupTitle="" GroupCode="" GroupID="">
And after this can you please give me logic, if I want to remove particular attribute while I am doing the grouping.
do you need only one group?
it appears that this XML has only one group,
you could do like below than
I remember I gave you a grouping solution in an earlier question,
you have cut out the grouping aspect of it
So I assume you no longer need that and rely on the fact that you only have one group
It also has a logic for removing group attributes
it appears that this XML has only one group,
you could do like below than
I remember I gave you a grouping solution in an earlier question,
you have cut out the grouping aspect of it
So I assume you no longer need that and rely on the fact that you only have one group
It also has a logic for removing group attributes
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:strip-space elements="*"/>
<xsl:output indent="yes"/>
<xsl:template match="*">
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:apply-templates select="node()"/>
<xsl:if test="self::navigation">
<node GroupTitle="{//@GroupTitle[1]}" GroupCode="{//@GroupCode[1]}" GroupID="{//@GroupID[1]}">
<nodes>
<xsl:apply-templates select="node()" mode="group"></xsl:apply-templates>
</nodes>
</node>
</xsl:if>
</xsl:copy>
</xsl:template>
<xsl:template match="*[normalize-space(@GroupCode) and not(*[not(normalize-space(@GroupCode))])]"/>
<xsl:template match="node[normalize-space(@GroupCode)]" mode="group">
<xsl:copy>
<xsl:apply-templates select="@*" mode="group"/>
<xsl:apply-templates select="node()" mode="group"/>
</xsl:copy>
</xsl:template>
<xsl:template match="node" mode="group">
<xsl:apply-templates select="node()" mode="group"/>
</xsl:template>
<xsl:template match="*" mode="group"/>
<xsl:template match="@*" mode="group">
<xsl:attribute name="{name()}">
<xsl:value-of select="."/>
</xsl:attribute>
</xsl:template>
<!-- node attributes to be deleted have an empty template each -->
<xsl:template match="@GroupTitle" mode="group"/>
<xsl:template match="@GroupCode" mode="group"/>
<xsl:template match="@GroupID" mode="group"/>
</xsl:stylesheet>
ASKER
Hi Gertone,
Many thanks for your code, it worked for me!!, but really going above my head.
Can you please write your comments or if you can help me to understand your code.
Thanks.
Many thanks for your code, it worked for me!!, but really going above my head.
Can you please write your comments or if you can help me to understand your code.
Thanks.
ASKER
Hi Gertone,
One more problem, the grouping is not for only one group.
Grouping can be multiple, so there can be lots of Groupcodes in the xml.
Please suggest how to get it as above code is working for one group and the code provided by you for grouping, how can I merge it here.
Please suggest!!
One more problem, the grouping is not for only one group.
Grouping can be multiple, so there can be lots of Groupcodes in the xml.
Please suggest how to get it as above code is working for one group and the code provided by you for grouping, how can I merge it here.
Please suggest!!
ASKER
Hi Gertone,
I modified your above xslt code as below for multiple grouping, please suggest if any modifcation is required.
I modified your above xslt code as below for multiple grouping, please suggest if any modifcation is required.
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:strip-space elements="*"/>
<xsl:output indent="yes"/>
<xsl:variable name="linkURL" select="'/system/ASPX/Link.aspx?ID='"/>
<xsl:key name="nodesByGroupsCode" match="*[node[not(@GroupCode)]]" use="@GroupCode" />
<xsl:template match="*">
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:apply-templates select="node()"/>
<xsl:if test="self::navigation">
<xsl:for-each select="//node[generate-id() = generate-id(key('nodesByGroupsCode', @GroupCode)[1])]">
<node GroupTitle="{@GroupTitle}" GroupCode="{@GroupCode}" Url="{$linkURL}{@GroupID}">
<nodes>
<xsl:for-each select="key('nodesByGroupsCode', @GroupCode)">
<xsl:copy>
<xsl:apply-templates select="@*" mode="group"/>
<xsl:apply-templates select="node()" mode="group"></xsl:apply-templates>
</xsl:copy>
</xsl:for-each>
</nodes>
</node>
</xsl:for-each>
</xsl:if>
</xsl:copy>
</xsl:template>
<xsl:template match="*[normalize-space(@GroupCode) and not(*[not(normalize-space(@GroupCode))])]"/>
<xsl:template match="node[normalize-space(@GroupCode)]" mode="group">
<xsl:copy>
<xsl:apply-templates select="@*" mode="group"/>
</xsl:copy>
</xsl:template>
<xsl:template match="*" mode="group"/>
<xsl:template match="@*" mode="group">
<xsl:attribute name="{name()}">
<xsl:value-of select="."/>
</xsl:attribute>
</xsl:template>
<!-- node attributes to be deleted have an empty template each -->
<xsl:template match="@GroupTitle" mode="group"/>
<xsl:template match="@GroupCode" mode="group"/>
<xsl:template match="@GroupID" mode="group"/>
</xsl:stylesheet>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks Gertone for you reply!!
I am going with your code with slight changes, one quick question can we also remove these attributes(GroupTitle,Grou pCode,Grou pID) from top whole XML as we have removed them in while doing grouping.
I mean when the grouping is done, all these attributes can be removed from whole xml.
Thanks
I am going with your code with slight changes, one quick question can we also remove these attributes(GroupTitle,Grou
I mean when the grouping is done, all these attributes can be removed from whole xml.
Thanks
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
welcome
Since 040. Skywards is in the list and 100 and 101 children are not,
I believe that teh discrimator is that you want to remove from the common processing,
those elements that are in a group and have no children that are not in a group.
Is that a correct assumption?
By only sending part of the XML (we are missing the navigation element, so selff:navigation does nothing)
we don't see the grouping mechanism work in the XML subset we have
If my assumption is right then all you need to do is add a template
<xsl:template match="*[normalize-space(@