Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 19th, 2016, 03:34 AM
Registered User
 
Join Date: Jan 2016
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Trouble with nested templates having same root node name

Hi I have an issue where the root node and child node have same names in the output .xml file which had to be formatted with XSLT for grouping issue.
The data of the XML looks like
<?xml version="1.0" encoding="UTF-8"?>
<DATA_DS>
<P_SVC_ID>NMW</P_SVC_ID>
<P_BUS_UNIT>NMWSC</P_BUS_UNIT>
<P_END_DATE>2016-01-16T08:00:00.000+00:00</P_END_DATE>
<LOGO><!--Generated by Oracle BI Publisher 11.1.1.7.0-->
<Properties>
<IMG_DIR_PATH>\images</IMG_DIR_PATH>
<IMGFILECAL>CWSCO.jpg</IMGFILECAL>
<IMGFILEHW>HWSCO.jpg</IMGFILEHW>
<IMGFILENM>NMWSC.jpg</IMGFILENM>
</Properties>
</LOGO>
<DATA_DS>
<G_2>
<RPTDEF>Report shows account balance of all customers under
30 60 90 or over 90 days old summarized
by AR balance per district
</RPTDEF>
</G_2>
<G_1>
<ENTITY_NAME>Aar </ENTITY_NAME>
<ACCT_ID>086343822256</ACCT_ID>
<SA_ID>086384522815</SA_ID>
<CM_DISTRICT>CG</CM_DISTRICT>
<SA_BAL_CURRENT>0</SA_BAL_CURRENT>
<SA_BAL_31_60>0</SA_BAL_31_60>
<SA_BAL_61_90>0</SA_BAL_61_90>
<SA_BAL_OVER_90>0</SA_BAL_OVER_90>
<TOT_AMT>0</TOT_AMT>
</G_1>
<G_1>
<ENTITY_NAME>Abe </ENTITY_NAME>
<ACCT_ID>864944456121</ACCT_ID>
<SA_ID>864944346341</SA_ID>
<CM_DISTRICT>CG</CM_DISTRICT>
<SA_BAL_CURRENT>0</SA_BAL_CURRENT>
<SA_BAL_31_60>0</SA_BAL_31_60>
<SA_BAL_61_90>0</SA_BAL_61_90>
<SA_BAL_OVER_90>0</SA_BAL_OVER_90>
<TOT_AMT>0</TOT_AMT>
</G_1>
<G_1>
<ENTITY_NAME>de la </ENTITY_NAME>
<ACCT_ID>748607834507</ACCT_ID>
<SA_ID>748607823446</SA_ID>
<CM_DISTRICT>WWA</CM_DISTRICT>
<SA_BAL_CURRENT>0</SA_BAL_CURRENT>
<SA_BAL_31_60>0</SA_BAL_31_60>
<SA_BAL_61_90>0</SA_BAL_61_90>
<SA_BAL_OVER_90>0</SA_BAL_OVER_90>
<TOT_AMT>0</TOT_AMT>
</G_1>
<G_1>
<ENTITY_NAME>deneva </ENTITY_NAME>
<ACCT_ID>803581423479</ACCT_ID>
<SA_ID>803581422316</SA_ID>
<CM_DISTRICT>WWA</CM_DISTRICT>
<SA_BAL_CURRENT>0</SA_BAL_CURRENT>
<SA_BAL_31_60>0</SA_BAL_31_60>
<SA_BAL_61_90>0</SA_BAL_61_90>
<SA_BAL_OVER_90>0</SA_BAL_OVER_90>
<TOT_AMT>0</TOT_AMT>
</G_1>
</DATA_DS>
</DATA_DS>


================================================== =======
Am trying to bring all elements but G_1 should be grouped on CM_DISTRICT values such as
<CM_DISTRICT>CA<G_1><ACCT_ID><ENTITY_NAME>.....</G_1></CM_DISTRICT>
So all CA value CM_DISTRICT are grouped under this element.

===============================================
I have been using the following XSL code:
================================================== ==
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes" />
<xsl:key name="DATA_DS" match="DATA_DS" use="DATA_DS"/>
<xsl:template match="DATA_DS">
<xsl:for-each select="DATA_DS">
<xsl:element name="DATA_DS">
<xsl:element name="P_SVC_ID"><xsl:value-of select="//P_SVC_ID" /></xsl:element>
<xsl:element name="P_BUS_UNIT"><xsl:value-of select="//P_BUS_UNIT"/></xsl:element>
<xsl:element name="P_END_DATE"><xsl:value-of select="//P_END_DATE"/></xsl:element>
<xsl:element name="LOGO">
<xsl:element name="Properties">
<xsl:element name="IMG_DIR_PATH"><xsl:value-of select="//IMG_DIR_PATH"/></xsl:element>
<xsl:element name="IMGFILECAL"><xsl:value-of select="//IMGFILECAL"/></xsl:element>
<xsl:element name="IMGFILEHW"><xsl:value-of select="//IMGFILEHW"/></xsl:element>
<xsl:element name="IMGFILENM"><xsl:value-of select="//IMGFILENM"/></xsl:element>
</xsl:element>
</xsl:element>
</xsl:element>
</xsl:for-each>
</xsl:template>
<xsl:key name="groups" match="DATA_DS/DATA_DS/G_1/CM_DISTRICT" use="."/>
<xsl:template match="/DATA_DS/DATA_DS">
<DATA_DS>
<xsl:apply-templates select="/DATA_DS/DATA_DS/G_1/CM_DISTRICT[generate-id() = generate-id(key('groups', .)[1])]"/>
</DATA_DS>
</xsl:template>
<xsl:template match="DATA_DS/DATA_DS/G_1/CM_DISTRICT">
<xsl:variable name="currentGroup" select="."/>
<CM_DISTRICT>
<xsl:value-of select="$currentGroup"/>

<xsl:for-each select="key('groups', $currentGroup)">
<G_1>
<ACCT_ID>
<xsl:value-of select="../ACCT_ID"/>
</ACCT_ID>
<ENTITY_NAME>
<xsl:value-of select="../ENTITY_NAME"/>
</ENTITY_NAME>
</G_1>
</xsl:for-each>
</CM_DISTRICT>
</xsl:template>
</xsl:stylesheet>



================================================== ==
I had separately achieved the grouping of this code as below with perfect results.
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes" />
<xsl:key name="groups" match="DATA_DS/DATA_DS/G_1/CM_DISTRICT" use="."/>
<xsl:template match="/DATA_DS/DATA_DS">
<DATA_DS>
<xsl:apply-templates select="/DATA_DS/DATA_DS/G_1/CM_DISTRICT[generate-id() = generate-id(key('groups', .)[1])]"/>
</DATA_DS>
</xsl:template>
<xsl:template match="DATA_DS/DATA_DS/G_1/CM_DISTRICT">
<xsl:variable name="currentGroup" select="."/>
<CM_DISTRICT>
<xsl:value-of select="$currentGroup"/>

<xsl:for-each select="key('groups', $currentGroup)">
<G_1>
<ACCT_ID>
<xsl:value-of select="../ACCT_ID"/>
</ACCT_ID>
<ENTITY_NAME>
<xsl:value-of select="../ENTITY_NAME"/>
</ENTITY_NAME>
</G_1>
</xsl:for-each>
</CM_DISTRICT>
</xsl:template>
</xsl:stylesheet>


This brings the output correctly for <DATA_DS>....</LOGO> </DATA_DS> but the rest of it is ignored..

But when i try to merge this code with the elements for <DATA_DS> till child node <DATA_DS> is included, it just brings the first result set only.How can i achieve this?

Last edited by AnuTri; January 19th, 2016 at 03:48 AM.. Reason: Has personal data.





Similar Threads
Thread Thread Starter Forum Replies Last Post
How to get rid of root node and child node... q1sevast XSLT 6 April 16th, 2012 02:56 AM
How do I show treeview root node sg48 BOOK: Beginning ASP.NET 2.0 and Databases 0 December 12th, 2008 02:49 PM
SiteMapDataSource won't find my root node... thenoseknows ASP.NET 2.0 Professional 0 October 31st, 2006 04:22 PM
Replacing New Root Node fauster XSLT 4 October 6th, 2006 11:17 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.