1 Reply Latest reply: Apr 28, 2013 6:26 AM by odie_63 RSS

    Need help in xslt

    SOAEnthusiast
      Hi,

      I need to write xslt, to convert below source into target xml.
      if stts_typ_cd is same for two blocks in below source, then in target multiple StatuscodeReason block should be generated for that stts_typ_cd. Any help will be really great. Thanks in advance

      source xml:-
      <?xml version="1.0" encoding="UTF-8" ?>
      <refDBGetStatusCodesUniverseByUserIdOutputCollection xmlns="http://xmlns.oracle.com/pcbpel/adapter/db/refDBGetStatusCodesUniverseByUserId">
      <refDBGetStatusCodesUniverseByUserIdOutput>
      <STTS_TYP_CD>1</STTS_TYP_CD>
      <ISSR_STTS_DSC>a</ISSR_STTS_DSC>
      <ISSR_STTS_CD_ADD_RSN_CD>b</ISSR_STTS_CD_ADD_RSN_CD>
      <ISSR_STTS_CD_ADD_RSN_DSC>c</ISSR_STTS_CD_ADD_RSN_DSC>
      <STTS_CD_PRMSSN>h</STTS_CD_PRMSSN>
      <GMP_USR_ID>123</GMP_USR_ID>
      </refDBGetStatusCodesUniverseByUserIdOutput>
      <refDBGetStatusCodesUniverseByUserIdOutput>
      <STTS_TYP_CD>2</STTS_TYP_CD>
      <ISSR_STTS_DSC>e</ISSR_STTS_DSC>
      <ISSR_STTS_CD_ADD_RSN_CD>f</ISSR_STTS_CD_ADD_RSN_CD>
      <ISSR_STTS_CD_ADD_RSN_DSC>g</ISSR_STTS_CD_ADD_RSN_DSC>
      <STTS_CD_PRMSSN>h</STTS_CD_PRMSSN>
      <GMP_USR_ID>123</GMP_USR_ID>
      </refDBGetStatusCodesUniverseByUserIdOutput>
      <refDBGetStatusCodesUniverseByUserIdOutput>
      <STTS_TYP_CD>1</STTS_TYP_CD>
      <ISSR_STTS_DSC>a</ISSR_STTS_DSC>
      <ISSR_STTS_CD_ADD_RSN_CD>i</ISSR_STTS_CD_ADD_RSN_CD>
      <ISSR_STTS_CD_ADD_RSN_DSC>j</ISSR_STTS_CD_ADD_RSN_DSC>
      <STTS_CD_PRMSSN>h</STTS_CD_PRMSSN>
      <GMP_USR_ID>123</GMP_USR_ID>
      </refDBGetStatusCodesUniverseByUserIdOutput>
      </refDBGetStatusCodesUniverseByUserIdOutputCollection>

      Target XML is :-
      <?xml version = '1.0' encoding = 'UTF-8'?>
      <ns1:GetStatusCodesUniverseByUserIdResMsg xmlns:ns1="http://xmlns.eginniemae.net/EntityService/GMEP/IssuerEntityComposite/GetStatusCodesUniverseByUserId/V1">
      <ns1:PermissionCode>
      <issuer:StatusCodePermission xmlns:issuer="http://xmlns.eginniemae.net/EntityModels/GMEP/Issuer/V1">
      <ns2:PermissionList xmlns:ns2="http://xmlns.eginniemae.net/EntityModels/GMEP/Common/V1">
      <ns2:Permission>h</ns2:Permission>
      </ns2:PermissionList>
      </issuer:StatusCodePermission>
      </ns1:PermissionCode>
      <ns1:StatusCodesAndReasonCodes>
      <issuer:IssuerStatus xmlns:issuer="http://xmlns.eginniemae.net/EntityModels/GMEP/Issuer/V1">
      <issuer:StatusCodeId>1</issuer:StatusCodeId>
      <issuer:StatusCodeDescription>a</issuer:StatusCodeDescription>
      <issuer:StatuscodeReasonList>
      <issuer:StatuscodeReason>
      <issuer:ReasonCode>b</issuer:ReasonCode>
      <issuer:ReasonDescription>c</issuer:ReasonDescription>
      </issuer:StatuscodeReason>
      <issuer:StatuscodeReason>
      <issuer:ReasonCode>i</issuer:ReasonCode>
      <issuer:ReasonDescription>j</issuer:ReasonDescription>
      </issuer:StatuscodeReason>
      </issuer:StatuscodeReasonList>
      </issuer:IssuerStatus>
      <issuer:IssuerStatus xmlns:issuer="http://xmlns.eginniemae.net/EntityModels/GMEP/Issuer/V1">
      <issuer:StatusCodeId>2</issuer:StatusCodeId>
      <issuer:StatusCodeDescription>e</issuer:StatusCodeDescription>
      <issuer:StatuscodeReasonList>
      <issuer:StatuscodeReason>
      <issuer:ReasonCode>f</issuer:ReasonCode>
      <issuer:ReasonDescription>g</issuer:ReasonDescription>
      </issuer:StatuscodeReason>
      </issuer:StatuscodeReasonList>
      </issuer:IssuerStatus>
      </ns1:StatusCodesAndReasonCodes>
      </ns1:GetStatusCodesUniverseByUserIdResMsg>
        • 1. Re: Need help in xslt
          odie_63
          SOAEnthusiast wrote:
          if stts_typ_cd is same for two blocks in below source, then in target multiple StatuscodeReason block should be generated for that stts_typ_cd.
          You have to use a grouping technique for that.
          The choice depends on what your XSLT processor supports : XSLT 1.0 or 2.0 ?

          If XSLT 1.0 only, use the "Muenchian" method :
          <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
            xmlns:def="http://xmlns.oracle.com/pcbpel/adapter/db/refDBGetStatusCodesUniverseByUserId"
            xmlns:ns1="http://xmlns.eginniemae.net/EntityService/GMEP/IssuerEntityComposite/GetStatusCodesUniverseByUserId/V1"
            xmlns:ns2="http://xmlns.eginniemae.net/EntityModels/GMEP/Common/V1"
            xmlns:issuer="http://xmlns.eginniemae.net/EntityModels/GMEP/Issuer/V1"
            exclude-result-prefixes="def">
            
            <xsl:output method="xml" indent="yes"/>
            <xsl:key name="StatusCodes" match="def:refDBGetStatusCodesUniverseByUserIdOutput" use="def:STTS_TYP_CD"/>
            <xsl:key name="Permissions" match="def:refDBGetStatusCodesUniverseByUserIdOutput" use="def:STTS_CD_PRMSSN"/>
            
            <xsl:template match="/def:refDBGetStatusCodesUniverseByUserIdOutputCollection">
              <ns1:GetStatusCodesUniverseByUserIdResMsg>
            
                <ns1:PermissionCode>
                  <issuer:StatusCodePermission>
                    <ns2:PermissionList>
                      <xsl:for-each select="def:refDBGetStatusCodesUniverseByUserIdOutput[count(. | key('Permissions', def:STTS_CD_PRMSSN)[1]) = 1]">
                    <ns2:Permission><xsl:value-of select="def:STTS_CD_PRMSSN"/></ns2:Permission>
                        </xsl:for-each>
                    </ns2:PermissionList>
                  </issuer:StatusCodePermission>
                </ns1:PermissionCode>
                
                <ns1:StatusCodesAndReasonCodes>
                  <xsl:apply-templates select="def:refDBGetStatusCodesUniverseByUserIdOutput[count(. | key('StatusCodes', def:STTS_TYP_CD)[1]) = 1]"/>
                </ns1:StatusCodesAndReasonCodes>
              
              </ns1:GetStatusCodesUniverseByUserIdResMsg>
            </xsl:template>
            
            <xsl:template match="def:refDBGetStatusCodesUniverseByUserIdOutput">
              <issuer:IssuerStatus>
              
                <issuer:StatusCodeId><xsl:value-of select="def:STTS_TYP_CD"/></issuer:StatusCodeId>
                <issuer:StatusCodeDescription><xsl:value-of select="def:ISSR_STTS_DSC"/></issuer:StatusCodeDescription>
                
                <issuer:StatuscodeReasonList>
                  <xsl:for-each select="key('StatusCodes', def:STTS_TYP_CD)">
                    <issuer:StatuscodeReason>
                      <issuer:ReasonCode><xsl:value-of select="def:ISSR_STTS_CD_ADD_RSN_CD"/></issuer:ReasonCode>
                      <issuer:ReasonDescription><xsl:value-of select="def:ISSR_STTS_CD_ADD_RSN_DSC"/></issuer:ReasonDescription>
                    </issuer:StatuscodeReason>
                  </xsl:for-each>
                </issuer:StatuscodeReasonList>
                
              </issuer:IssuerStatus>
            </xsl:template>
          
          </xsl:stylesheet>
          {code}
           
          
          If you have XSLT 2.0 support then use built-in grouping instructions : 
          {code:xml}
          <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
            xpath-default-namespace="http://xmlns.oracle.com/pcbpel/adapter/db/refDBGetStatusCodesUniverseByUserId"
            xmlns:ns1="http://xmlns.eginniemae.net/EntityService/GMEP/IssuerEntityComposite/GetStatusCodesUniverseByUserId/V1"
            xmlns:ns2="http://xmlns.eginniemae.net/EntityModels/GMEP/Common/V1"
            xmlns:issuer="http://xmlns.eginniemae.net/EntityModels/GMEP/Issuer/V1">
            <xsl:output method="xml" indent="yes"/>
            
            <xsl:template match="/refDBGetStatusCodesUniverseByUserIdOutputCollection">
              <ns1:GetStatusCodesUniverseByUserIdResMsg>
          
                <ns1:PermissionCode>
                  <issuer:StatusCodePermission>
                    <ns2:PermissionList>
                      <xsl:for-each-group select="refDBGetStatusCodesUniverseByUserIdOutput" group-by="STTS_CD_PRMSSN">
                        <ns2:Permission><xsl:value-of select="current-grouping-key()"/></ns2:Permission>
                      </xsl:for-each-group>
                    </ns2:PermissionList>
                  </issuer:StatusCodePermission>
                </ns1:PermissionCode>
              
                <ns1:StatusCodesAndReasonCodes>
                  <xsl:for-each-group select="refDBGetStatusCodesUniverseByUserIdOutput" group-by="STTS_TYP_CD">
                    <issuer:IssuerStatus>
                      <issuer:StatusCodeId><xsl:value-of select="current-grouping-key()"/></issuer:StatusCodeId>
                      <issuer:StatusCodeDescription><xsl:value-of select="current-group()[1]/ISSR_STTS_DSC"/></issuer:StatusCodeDescription>
                      <issuer:StatuscodeReasonList>
                        <xsl:for-each select="current-group()">
                              <issuer:StatuscodeReason>
                            <issuer:ReasonCode><xsl:value-of select="ISSR_STTS_CD_ADD_RSN_CD"/></issuer:ReasonCode>
                            <issuer:ReasonDescription><xsl:value-of select="ISSR_STTS_CD_ADD_RSN_DSC"/></issuer:ReasonDescription>
                          </issuer:StatuscodeReason>
                        </xsl:for-each>
                      </issuer:StatuscodeReasonList>
                    </issuer:IssuerStatus>
                      </xsl:for-each-group>
                </ns1:StatusCodesAndReasonCodes>
              
              </ns1:GetStatusCodesUniverseByUserIdResMsg>
            </xsl:template>
          
          </xsl:stylesheet>
          {code}