glfnute 0 Newbie Poster

Still fairly new to XSLT would like to ask for some expert direction on how to solve what I think should be easy, just not for me ... I am parsing several different input sources to output one result XML structure. During the parsing, I am doing some pre-checks and putting any "error" conditions into the values. I would like to be able to count the number of "errors" that have accumulated into another field. Here is a sample of the output:

<?xml version="1.0" encoding="UTF-8"?>
<MergeSet>
   <MergeQual>
      <MergeSiteID>ADOA-2COGKZ</MergeSiteID>
      <MergeSiteExtID/>
      <MergeSiteName>PANASONIC CORP [200000000014117]</MergeSiteName>
      <DupSiteID>ADOA-3ZFGLN</DupSiteID>
      <DupSiteExtID/>
      <DupSiteName>PANASONIC SYSTEM SOLUTIONS INFRASTRUCTURE CO LTD             [200000000036436]</DupSiteName>
      <MergeTimeStamp>03/08/2011 10:19:03</MergeTimeStamp>
      <MergeRequestor>A.Vogel</MergeRequestor>
      <SiteTypeChk>Error: Master Site Type = Account cannot merge with Dup Site Type = UPC</SiteTypeChk>
      <DSOneIndustryChk>5. High Tech</DSOneIndustryChk>
      <DSOneSegmentChk>5.1 Consumer Electronics</DSOneSegmentChk>
      <SiteCountryChk>Error: Master SiteCountry = Japan cannot merge with Dup SiteCountry: Japana</SiteCountryChk>
      <OwnerChk>Error: Owner Hierarchy mismatch, Primary Owner: M.Tasaka not in hierarchy of Dup Site owner: 3DS</OwnerChk>
      <AdminDataChk>Error: Dup AdminData is set to Y</AdminDataChk>
      <VisibilityChk>Error: Master Site Visibility = BT cannot merge with Dup Site Visibility: VS</VisibilityChk>
      <Send4ProcessingChk>Warning: Dup Send_for_processing is set to Y, merge will be delayed</Send4ProcessingChk>
      <SalesTerritoryChk/>
      <SalesCompTeamChk/>
      <MergeErrorCount>0</MergeErrorCount>
   </MergeQual>
</MergeSet>

so in this example, <MergeErrorCount> would be 4

Here is my XSLT:

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"
    xmlns:bpws="http://schemas.xmlsoap.org/ws/2003/03/business-process/">
    <xsl:output method="xml" indent="yes"/>
    
    <xsl:variable name="PickLists" select="document('Picklist.xml')"/>
    <xsl:variable name="MergeSite" select="document('SampleParent.xml')"/>
    <xsl:variable name="DupSite" select="document('SampleDup.xml')"/>
    <xsl:variable name="SiteTypeMap" select="document('SiteTypeMap.xml')"/>
    <xsl:variable name="SiteVisMap" select="document('SiteVisMap.xml')"/>
    <xsl:variable name="UserTree" select="document('UserTree.xml')"/>
    <xsl:template match="*:MergeSet">
        <xsl:copy>
            <xsl:apply-templates select="*:MergeQual"/>
        </xsl:copy>
    </xsl:template>
    <xsl:template match="*:MergeQual"> 
        <xsl:copy>
            <xsl:element name="MergeSiteID" ><xsl:value-of select="$MergeSite/*:AccountWS_AccountQueryPage_Output/*:ListOfAccount/*:Account/*:AccountId"/></xsl:element>
            <xsl:element name="MergeSiteExtID" ><xsl:value-of
                select="$MergeSite/*:AccountWS_AccountQueryPage_Output/*:ListOfAccount/*:Account/*:ExternalSystemId"/></xsl:element>
            <xsl:element name="MergeSiteName" ><xsl:value-of select="$MergeSite/*:AccountWS_AccountQueryPage_Output/*:ListOfAccount/*:Account/*:AccountName"/></xsl:element>
            <xsl:element name="DupSiteID" ><xsl:value-of select="$DupSite/*:AccountWS_AccountQueryPage_Output/*:ListOfAccount/*:Account/*:AccountId"/></xsl:element>
            <xsl:element name="DupSiteExtID" ><xsl:value-of
                select="$DupSite/*:AccountWS_AccountQueryPage_Output/*:ListOfAccount/*:Account/*:ExternalSystemId"/></xsl:element>
            <xsl:element name="DupSiteName" ><xsl:value-of select="$DupSite/*:AccountWS_AccountQueryPage_Output/*:ListOfAccount/*:Account/*:AccountName"/></xsl:element>
            <xsl:element name="MergeTimeStamp" ><xsl:value-of select="*:MergeTimeStamp"/></xsl:element>
            <xsl:element name="MergeRequestor" ><xsl:value-of select="substring(*:MergeRequestor,1,64)"/></xsl:element>
            <xsl:element name="SiteTypeChk">
                <xsl:choose>
                    <xsl:when test="$SiteTypeMap/*:rows/*:row[*:MasterType=$MergeSite/*:AccountWS_AccountQueryPage_Output/*:ListOfAccount/*:Account/*:plz_DS1_Site_Type][*:DupType=$DupSite/*:AccountWS_AccountQueryPage_Output/*:ListOfAccount/*:Account/*:plz_DS1_Site_Type]/*:ResultType != 'XXX'">
                        <xsl:value-of select="$SiteTypeMap/*:rows/*:row[*:MasterType=$MergeSite/*:AccountWS_AccountQueryPage_Output/*:ListOfAccount/*:Account/*:plz_DS1_Site_Type][*:DupType=$DupSite/*:AccountWS_AccountQueryPage_Output/*:ListOfAccount/*:Account/*:plz_DS1_Site_Type]/*:ResultType"/>
                    </xsl:when>
                    <xsl:otherwise>
                        <xsl:value-of select="concat('Error: Master Site Type = ',
                            $MergeSite/*:AccountWS_AccountQueryPage_Output/*:ListOfAccount/*:Account/*:plz_DS1_Site_Type,
                            ' cannot merge with Dup Site Type = ', $DupSite/*:AccountWS_AccountQueryPage_Output/*:ListOfAccount/*:Account/*:plz_DS1_Site_Type)"/></xsl:otherwise>
                </xsl:choose>
            </xsl:element>
            <xsl:element name="DSOneIndustryChk">
                <xsl:choose>
                    <xsl:when test="$MergeSite/*:AccountWS_AccountQueryPage_Output/*:ListOfAccount/*:Account/*:plz_DS1_Site_Industry != ''">
                        <xsl:choose>
                        <xsl:when test="$DupSite/*:AccountWS_AccountQueryPage_Output/*:ListOfAccount/*:Account/*:plz_DS1_Site_Industry != ''">
                            <xsl:choose>
                            <xsl:when test="$MergeSite/*:AccountWS_AccountQueryPage_Output/*:ListOfAccount/*:Account/*:plz_DS1_Site_Industry = $DupSite/*:AccountWS_AccountQueryPage_Output/*:ListOfAccount/*:Account/*:plz_DS1_Site_Industry">
                                <xsl:value-of select="$MergeSite/*:AccountWS_AccountQueryPage_Output/*:ListOfAccount/*:Account/*:plz_DS1_Site_Industry"/>
                            </xsl:when>
                            <xsl:otherwise>
                                <xsl:value-of select="concat('Error: Master DSOneIndustry = ', $MergeSite/*:AccountWS_AccountQueryPage_Output/*:ListOfAccount/*:Account/*:plz_DS1_Site_Industry, ' cannot merge with Dup DSOneIndustry: ', $DupSite/*:AccountWS_AccountQueryPage_Output/*:ListOfAccount/*:Account/*:plz_DS1_Site_Industry)"/>
                            </xsl:otherwise>
                            </xsl:choose>
                        </xsl:when>
                        <xsl:otherwise>
                            <xsl:value-of select="$MergeSite/*:AccountWS_AccountQueryPage_Output/*:ListOfAccount/*:Account/*:plz_DS1_Site_Industry"/>
                        </xsl:otherwise>
                        </xsl:choose>
                    </xsl:when>
                    <xsl:otherwise>
                        <xsl:value-of select="$DupSite/*:AccountWS_AccountQueryPage_Output/*:ListOfAccount/*:Account/*:plz_DS1_Site_Industry"/>
                    </xsl:otherwise>               
                </xsl:choose>
            </xsl:element>
            <xsl:element name="DSOneSegmentChk">
                <xsl:choose>
                    <xsl:when test="$MergeSite/*:AccountWS_AccountQueryPage_Output/*:ListOfAccount/*:Account/*:plz_DS1_Site_SubIndustry = ''">
                        <xsl:value-of select="$DupSite/*:AccountWS_AccountQueryPage_Output/*:ListOfAccount/*:Account/*:plz_DS1_Site_SubIndustry"/>
                    </xsl:when>
                    <xsl:otherwise>
                        <xsl:value-of select="$MergeSite/*:AccountWS_AccountQueryPage_Output/*:ListOfAccount/*:Account/*:plz_DS1_Site_SubIndustry"/>
                    </xsl:otherwise>               
                </xsl:choose>
            </xsl:element>
            <xsl:element name="SiteCountryChk">
                <xsl:choose>
                    <xsl:when test="$MergeSite/*:AccountWS_AccountQueryPage_Output/*:ListOfAccount/*:Account/*:plCompany_Country = $DupSite/*:AccountWS_AccountQueryPage_Output/*:ListOfAccount/*:Account/*:plCompany_Country">
                        <xsl:value-of select="$MergeSite/*:AccountWS_AccountQueryPage_Output/*:ListOfAccount/*:Account/*:plCompany_Country"/>
                    </xsl:when>
                    <xsl:otherwise>
                        <xsl:value-of select="concat('Error: Master SiteCountry = ', $MergeSite/*:AccountWS_AccountQueryPage_Output/*:ListOfAccount/*:Account/*:plCompany_Country, ' cannot merge with Dup SiteCountry: ', $DupSite/*:AccountWS_AccountQueryPage_Output/*:ListOfAccount/*:Account/*:plCompany_Country)"/>
                    </xsl:otherwise>               
                </xsl:choose>
            </xsl:element>
            <xsl:element name="OwnerChk">
                <xsl:choose>
                    <xsl:when test="$MergeSite/*:AccountWS_AccountQueryPage_Output/*:ListOfAccount/*:Account/*:Owner = $DupSite/*:AccountWS_AccountQueryPage_Output/*:ListOfAccount/*:Account/*:Owner">
                        <xsl:value-of select="$MergeSite/*:AccountWS_AccountQueryPage_Output/*:ListOfAccount/*:Account/*:Owner"/>
                    </xsl:when>
                    <xsl:otherwise>
                        <xsl:choose>
                        <xsl:when test="$UserTree/*:rows/*:row[*:Alias=$MergeSite/*:AccountWS_AccountQueryPage_Output/*:ListOfAccount/*:Account/*:Owner]/*:Depth > $UserTree/*:rows/*:row[*:Alias=$DupSite/*:AccountWS_AccountQueryPage_Output/*:ListOfAccount/*:Account/*:Owner]/*:Depth">
                            <xsl:choose>
                            <xsl:when test="contains($UserTree/*:rows/*:row[*:Alias=$MergeSite/*:AccountWS_AccountQueryPage_Output/*:ListOfAccount/*:Account/*:Owner]/*:Lineage, $UserTree/*:rows/*:row[*:Alias=$DupSite/*:AccountWS_AccountQueryPage_Output/*:ListOfAccount/*:Account/*:Owner]/*:Node)">
                                <xsl:value-of select="$MergeSite/*:AccountWS_AccountQueryPage_Output/*:ListOfAccount/*:Account/*:Owner"/>
                            </xsl:when>
                            <xsl:otherwise>
                                <xsl:value-of select="concat('Error: Owner Hierarchy mismatch, Primary Owner: ', $MergeSite/*:AccountWS_AccountQueryPage_Output/*:ListOfAccount/*:Account/*:Owner, ' not in hierarchy of Dup Site owner: ', $DupSite/*:AccountWS_AccountQueryPage_Output/*:ListOfAccount/*:Account/*:Owner)"/>
                            </xsl:otherwise>
                            </xsl:choose>
                        </xsl:when>
                        <xsl:otherwise>
                            <xsl:value-of select="concat('Error: Owner Hierarchy mismatch, Primary Owner: ', $MergeSite/*:AccountWS_AccountQueryPage_Output/*:ListOfAccount/*:Account/*:Owner, ' not in hierarchy of Dup Site owner: ', $DupSite/*:AccountWS_AccountQueryPage_Output/*:ListOfAccount/*:Account/*:Owner)"/>
                        </xsl:otherwise>
                        </xsl:choose>
                    </xsl:otherwise>               
                </xsl:choose>
            </xsl:element>
            <xsl:element name="AdminDataChk">
                <xsl:choose>
                    <xsl:when test="$MergeSite/*:AccountWS_AccountQueryPage_Output/*:ListOfAccount/*:Account/*:bAdmin_Data != 'Y'">
                        <xsl:choose>
                            <xsl:when test="$DupSite/*:AccountWS_AccountQueryPage_Output/*:ListOfAccount/*:Account/*:bAdmin_Data != 'Y'">
                                <xsl:value-of select="'N'"/>
                            </xsl:when>
                            <xsl:otherwise>
                                <xsl:value-of select="'Error: Dup AdminData is set to Y'"/>
                            </xsl:otherwise>
                        </xsl:choose>
                    </xsl:when>
                    <xsl:otherwise>
                        <xsl:value-of select="'Error: Merge AdminData is set to Y'"/>
                    </xsl:otherwise>               
                </xsl:choose>
            </xsl:element>
            <xsl:element name="VisibilityChk">
                <xsl:choose>
                    <xsl:when test="$SiteTypeMap/*:rows/*:row[*:MasterVisibility=$MergeSite/*:AccountWS_AccountQueryPage_Output/*:ListOfAccount/*:Account/*:plChannel][*:DupVisibility=$DupSite/*:AccountWS_AccountQueryPage_Output/*:ListOfAccount/*:Account/*:plChannel]/*:ResultVisibility != 'XXX'">
                        <xsl:value-of select="$SiteTypeMap/*:rows/*:row[*:MasterVisibility=$MergeSite/*:AccountWS_AccountQueryPage_Output/*:ListOfAccount/*:Account/*:plChannel][*:DupVisibility=$DupSite/*:AccountWS_AccountQueryPage_Output/*:ListOfAccount/*:Account/*:plChannel]/*:ResultVisibility"/>
                    </xsl:when>
                    <xsl:otherwise>
                        <xsl:value-of select="concat('Error: Master Site Visibility = ', $MergeSite/*:AccountWS_AccountQueryPage_Output/*:ListOfAccount/*:Account/*:plChannel, ' cannot merge with Dup Site Visibility: ', $DupSite/*:AccountWS_AccountQueryPage_Output/*:ListOfAccount/*:Account/*:plChannel)"/></xsl:otherwise>
                </xsl:choose>
            </xsl:element>
            <xsl:element name="Send4ProcessingChk">
                <xsl:choose>
                    <xsl:when test="$MergeSite/*:AccountWS_AccountQueryPage_Output/*:ListOfAccount/*:Account/*:IndexedBoolean0 != 'Y'">
                        <xsl:choose>
                            <xsl:when test="$DupSite/*:AccountWS_AccountQueryPage_Output/*:ListOfAccount/*:Account/*:IndexedBoolean0 != 'Y'">
                                <xsl:value-of select="'N'"/>
                            </xsl:when>
                            <xsl:otherwise>
                                <xsl:value-of select="'Warning: Dup Send_for_processing is set to Y,
                                    merge will be delayed'"/>
                            </xsl:otherwise>
                        </xsl:choose>
                    </xsl:when>
                    <xsl:otherwise>
                        <xsl:value-of select="'Warning: Merge Send_for_processing is set to Y,
                            merge will be delayed'"/>
                    </xsl:otherwise>               
                </xsl:choose>
            </xsl:element>
            <xsl:element name="SalesTerritoryChk" ><xsl:value-of select="substring(*:SalesTerritoryChk,1,15)"/></xsl:element>
            <xsl:element name="SalesCompTeamChk" ><xsl:value-of select="substring(*:SalesCompTeamChk,1,15)"/></xsl:element>
            <xsl:element name="MergeErrorCount">
                <xsl:for-each select="node()[starts-with(.,'Error:')]"/>          
                <xsl:value-of select="count(node()[starts-with(.,'Error:')])"/>
            </xsl:element>
        </xsl:copy>
    </xsl:template>
    <xsl:template match="*">
        <xsl:copy>
            <xsl:value-of select="."/>
        </xsl:copy>
    </xsl:template>
</xsl:stylesheet>

Thanks in advance for any advice/direction.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.