IBM webMethods Hybrid Integration

IBM webMethods Hybrid Integration

Join this online group to communicate across IBM product users and experts by sharing advice and best practices with peers and staying up to date regarding product enhancements.

 View Only
Expand all | Collapse all

Problem with repeat data in XML to XML transformation

  • 1.  Problem with repeat data in XML to XML transformation

    Posted Sat June 10, 2006 03:53 AM

    I have xml that looks like this

    
    <pavement_x0020_Conditions>
    <NetworkID>EVERETT</NetworkID>
    <Name>SNOHOMISH COUNTY (PAINE FIELD)</Name>
    <BranchID>AEHPF</BranchID>
    <SectionID>01</SectionID>
    <Surface>AC</Surface>
    <Condition>94</Condition>
    <DATE>2005-03-03T00:00:00</DATE>
    <SAMPLES>37</SAMPLES>
    </pavement_x0020_Conditions>
    
    <pavement_x0020_Conditions>
    <NetworkID>PUYALLUP</NetworkID>
    <Name>PIERCE COUNTY - THUN FIELD</Name>
    <BranchID>A02TH</BranchID>
    <SectionID>03</SectionID>
    <Surface>AC</Surface>
    <Condition>77</Condition>
    <DATE>2005-03-03T00:00:00</DATE>
    <SAMPLES>6</SAMPLES>
    </pavement_x0020_Conditions>
    <pavement_x0020_Conditions>
    <NetworkID>PUYALLUP</NetworkID>
    <Name>PIERCE COUNTY - THUN FIELD</Name>
    <BranchID>AH1TH</BranchID>
    <SectionID>01</SectionID>
    <Surface>AC</Surface>
    <Condition>98</Condition>
    <DATE>2005-03-03T00:00:00</DATE>
    <SAMPLES>2</SAMPLES>
    </pavement_x0020_Conditions>
    <pavement_x0020_Conditions>
    <NetworkID>PUYALLUP</NetworkID>
    <Name>PIERCE COUNTY - THUN FIELD</Name>
    <BranchID>A02TH</BranchID>
    <SectionID>02</SectionID>
    <Surface>AC</Surface>
    <Condition>78</Condition>
    <DATE>2005-03-03T00:00:00</DATE>
    <SAMPLES>7</SAMPLES>
    </pavement_x0020_Conditions>

    and I need to transform it to this (the data changes, obviously. Two different databases)

    
    
    <airports>
    
    <airport name="Benson">
    <map>data/benson.swf</map>
    <branches>
    
    <pavement_x0020_Branch>
    <DATE>2003-01-25T00:00:00</DATE>
    <SAMPLES>28</SAMPLES>
    <BranchID>A01BN</BranchID>
    <SectionID>10</SectionID>
    <Surface>AC</Surface>
    <Condition>100</Condition>
    </pavement_x0020_Branch>
    
    <pavement_x0020_Branch>
    <DATE>2003-01-25T00:00:00</DATE>
    <SAMPLES>55</SAMPLES>
    <BranchID>RW1028BN</BranchID>
    <SectionID>10</SectionID>
    <Surface>AC</Surface>
    <Condition>99</Condition>
    </pavement_x0020_Branch>
    
    <pavement_x0020_Branch>
    <DATE>2003-01-25T00:00:00</DATE>
    <SAMPLES>1</SAMPLES>
    <BranchID>TWABN</BranchID>
    <SectionID>10</SectionID>
    <Surface>AC</Surface>
    <Condition>98</Condition>
    </pavement_x0020_Branch>
    
    </branches>
    </airport>
    
    <airport name="Bisbee">
    <map>data/bisbee.swf</map>
    <branches>
    
    <pavement_x0020_Branch>
    <DATE>2003-01-25T00:00:00</DATE>
    <SAMPLES>59</SAMPLES>
    <BranchID>RW1735BM</BranchID>
    <SectionID>10</SectionID>
    <Surface>AAC</Surface>
    <Condition>90</Condition>
    </pavement_x0020_Branch>
    
    <pavement_x0020_Branch>
    <DATE>2003-01-25T00:00:00</DATE>
    <SAMPLES>50</SAMPLES>
    <BranchID>TWABM</BranchID>
    <SectionID>10</SectionID>
    <Surface>AC</Surface>
    <Condition>79</Condition>
    </pavement_x0020_Branch>
    
    <pavement_x0020_Branch>
    <DATE>2003-01-25T00:00:00</DATE>
    <SAMPLES>22</SAMPLES>
    <BranchID>A01BM</BranchID>
    <SectionID>10</SectionID>
    <Surface>AC</Surface>
    <Condition>90</Condition>
    </pavement_x0020_Branch>
    
    </branches>
    </airport>
    </airports>
    

    Here is the problem: I basically have to make from the the first snippet into from the second (the other nodes should stay the same). But if I make a parent node I think I will get something that looks like this:

    
    
    <airport name="Benson">
    <map>data/benson.swf</map>
    <branches>
    
    <pavement_x0020_Branch>
    <DATE>2003-01-25T00:00:00</DATE>
    <SAMPLES>28</SAMPLES>
    <BranchID>A01BN</BranchID>
    <SectionID>10</SectionID>
    <Surface>AC</Surface>
    <Condition>100</Condition>
    </pavement_x0020_Branch>
    
    </branches>
    </airport>
    
    <airport name="Benson">
    <map>data/benson.swf</map>
    <branches>
    
    <pavement_x0020_Branch>
    <DATE>2003-01-25T00:00:00</DATE>
    <SAMPLES>55</SAMPLES>
    <BranchID>RW1028BN</BranchID>
    <SectionID>10</SectionID>
    <Surface>AC</Surface>
    <Condition>99</Condition>
    </pavement_x0020_Branch>
    
    </branches>
    </airport>
    
    <airport name="Benson">
    <map>data/benson.swf</map>
    <branches>
    
    <pavement_x0020_Branch>
    <DATE>2003-01-25T00:00:00</DATE>
    <SAMPLES>1</SAMPLES>
    <BranchID>TWABN</BranchID>
    <SectionID>10</SectionID>
    <Surface>AC</Surface>
    <Condition>98</Condition>
    </pavement_x0020_Branch>
    
    </branches>
    </airport>
    

    Do you see my problem? I need some way to tell the transformer not to make a new node if the is the same. I tried using xsl:variabe and xsl:choose, but I’m afraid my know-how is a little limited.

    Thanks in advance for any help


    #webMethods
    #API-Management
    #Tamino


  • 2.  RE: Problem with repeat data in XML to XML transformation

    Posted Fri June 16, 2006 05:43 PM

    I prefer the Muenchian method in this case.
    http://www.jenitennison.com/xslt/grouping/muenchian.html

    I’m not exactly sure how your code looks, but you’d want something like:
    At the top,
    <xsl:key name=“paveConditionsByNetwork” match=“pavement_x0020_Conditions” use=“NetworkID”/>


    <xsl:apply-templates select=“pavement_x0020_Conditions[count(. | key(‘paveConditionsByNetwork’, NetworkID)[1]) = 1]”/>


    <xsl:template match=“pavement_x0020_Conditions”>

    .. individual info.

    You could also do this by using following-sibling:: or preceding-sibling:: axis, but that is a bit of a hassle, and is much slower.


    #Tamino
    #webMethods
    #API-Management