2
votes

i have asked with the same question but not with the namespace

i have an xml like..this

<?xml version = '1.0' encoding = 'UTF-8'?>
<FinalDbGetUserId>
  <FinalDbGetUserIdOutputCollection xmlns:ns0="http://xmlns.oracle.com/pcbpel/adapter/db/FinalDbGetUserId"
                                    xmlns="http://xmlns.oracle.com/pcbpel/adapter/db/FinalDbGetUserId">
    <ns0:USERUBSCRIBERS>
      <ns0:USER_ID>237</ns0:USER_ID>
      <ns0:BusinessEntity>
        <ns0:NEVADA_BUSINESS_ID>NV0511201114</ns0:NEVADA_BUSINESS_ID>
        <ns0:BUSINESS_ENTITY_ID>207</ns0:BUSINESS_ENTITY_ID>
      </ns0:BusinessEntity>
    </ns0:USERUBSCRIBERS>
    <ns0:USERUBSCRIBERS>
      <ns0:USER_ID>237</ns0:USER_ID>
      <ns0:BusinessEntity>
        <ns0:NEVADA_BUSINESS_ID>NV0511201119</ns0:NEVADA_BUSINESS_ID>
        <ns0:BUSINESS_ENTITY_ID>212</ns0:BUSINESS_ENTITY_ID>
      </ns0:BusinessEntity>
    </ns0:USERUBSCRIBERS>
    <ns0:USERUBSCRIBERS>
      <ns0:USER_ID>237</ns0:USER_ID>
      <ns0:BusinessEntity>
        <ns0:NEVADA_BUSINESS_ID>NV0511201129</ns0:NEVADA_BUSINESS_ID>
        <ns0:BUSINESS_ENTITY_ID>230</ns0:BUSINESS_ENTITY_ID>
      </ns0:BusinessEntity>
    </ns0:USERUBSCRIBERS>
  </FinalDbGetUserIdOutputCollection>
</FinalDbGetUserId>

output should be like

<FinalDbGetUserId>
  <FinalDbGetUserIdOutputCollection xmlns:ns0="http://xmlns.oracle.com/pcbpel/adapter/db/FinalDbGetUserId"
                                    xmlns="http://xmlns.oracle.com/pcbpel/adapter/db/FinalDbGetUserId">
    <ns0:USERUBSCRIBERS>
      <ns0:USER_ID>237</ns0:USER_ID>
      <ns0:BusinessEntity>
        <ns0:NEVADA_BUSINESS_ID>NV0511201114</ns0:NEVADA_BUSINESS_ID>
        <ns0:BUSINESS_ENTITY_ID>207</ns0:BUSINESS_ENTITY_ID>
      </ns0:BusinessEntity>
      <ns0:BusinessEntity>
        <ns0:NEVADA_BUSINESS_ID>NV0511201119</ns0:NEVADA_BUSINESS_ID>
        <ns0:BUSINESS_ENTITY_ID>212</ns0:BUSINESS_ENTITY_ID>
      </ns0:BusinessEntity>
      <ns0:BusinessEntity>
        <ns0:NEVADA_BUSINESS_ID>NV0511201129</ns0:NEVADA_BUSINESS_ID>
        <ns0:BUSINESS_ENTITY_ID>230</ns0:BUSINESS_ENTITY_ID>
      </ns0:BusinessEntity>
    </ns0:USERUBSCRIBERS>
  </FinalDbGetUserIdOutputCollection>
</FinalDbGetUserId>

Following is the below xslt, that i was trying and not getting the desired result

<xsl:stylesheet version="1.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:output omit-xml-declaration="yes" indent="yes"/>
 <xsl:strip-space elements="*"/>

 <xsl:key name="kuserID" match="USERUBSCRIBERS"  use="USER_ID"/>

 <xsl:template match="node()|@*">
     <xsl:copy>
       <xsl:apply-templates select="node()|@*">
         <xsl:sort select="USER_ID" data-type="number"/>
       </xsl:apply-templates>
     </xsl:copy>
 </xsl:template>


 <xsl:template match=
 "USERUBSCRIBERS|USER_ID
 |BusinessEntity"/>

 <xsl:template match=
  "USERUBSCRIBERS
    [generate-id()
    =
     generate-id(key('kuserID', USER_ID)[1])
     ]">
  <USERUBSCRIBERS>
   <xsl:copy-of select="USER_ID"/>
   <xsl:apply-templates mode="copy" select="key('kuserID',USER_ID)" />
  </USERUBSCRIBERS>
 </xsl:template>

 <xsl:template match="USERUBSCRIBERS" mode="copy">
  <BusinessEntity>
   <xsl:apply-templates/>
  </BusinessEntity>
 </xsl:template>
</xsl:stylesheet>

i am getting the output same as input and there is no change. may be i am doing mistake, but not getting what the mistake is .... trying to find it out

1
This is a very basic grouping question, what part of it are you finding difficult? Why do namespaces affect the problem? It's difficult to answer such questions without knowing where your difficulties lie - we don't know how much you know. Someone might just code it up for you, but I tend to avoid that - there's no guarantee that people will understand the code, and if they don't understand it, they tend to come straight back with another question.Michael Kay
Please accept one of the answers in the previous similar question which reflects best your requirements. That answer will be used to answer this following up.Emiliano Poggi

1 Answers

1
votes

Define xmlns:ns0="http://xmlns.oracle.com/pcbpel/adapter/db/FinalDbGetUserId" on your xsl:stylesheet element, then use the prefix ns0 anywhere in your stylesheet where you match or select elements from that namespace e.g. <xsl:key name="kuserID" match="ns0:USERUBSCRIBERS" use="ns0:USER_ID"/> and <xsl:sort select="ns0:USER_ID" data-type="number"/>.