XML Grouping problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jkoufala
    New Member
    • Mar 2007
    • 3

    XML Grouping problem

    Hi
    I am new to XSLT and i have a problem with grouping. What im trying to do is group using two elements as a unique identifier.
    This is output from another program which outputs the same element but if there are mulitple drawings it will repeat it several times each time with the next drawing number.

    e.g.

    child parent DrawingNo
    x y z
    x y z1
    x1 y1 z2

    to

    x y z,z1
    x1 y1 z2

    merging the two

    here is some of the XML to help


    - <row idx="1">
    <Child>105394 </Child>
    <Description>El ement 1</Description>
    <Parent>10538 8</Parent>
    <Drawing>102553 </Drawing>
    </row>
    - <row idx="2">
    <Child>105394 </Child>
    <Description>El ement 1</Description>
    <Parent>10538 8</Parent>
    <Drawing>102554 </Drawing>
    </row>
    - <row idx="3">
    <Child>105379 </Child>
    <Description>El ement 2</Description>
    <Parent>10538 1</Parent>
    <Drawing>102554 </Drawing>
    </row>


    I have another xsl file that uses the parent child relationship to create a tree structure (indenture level e.g. 0 is highest level parent, 1 is next child, 2 is 1's child etc) This is why combining the same elements into one is so important otherwise i will have the same element having duplicate records of the same children.
  • dorinbogdan
    Recognized Expert Contributor
    • Feb 2007
    • 839

    #2
    For grouping try to use xsl:sort. See this sample, which is part of an easy tutorial.

    Comment

    • jkoufala
      New Member
      • Mar 2007
      • 3

      #3
      Originally posted by dorinbogdan
      For grouping try to use xsl:sort. See this sample, which is part of an easy tutorial.

      This is not what i am doing. I have two identifiers.

      e.g.
      child parent DrawingNo
      x y z
      x y z1
      x w z5
      d y z2
      s f z3

      From this the two entries with child x AND parent y are the exact same element except the drawingNo. I need to combine these two

      x y z1, z2

      and the others need to remain the same

      x w z5
      d y z2
      s f z3

      see
      x w z5
      is a different element because it is related to a different parent, so it not the same and shouldnt be combined with
      x y z1,z2

      i need to group by child and parent combined

      HOW????

      Comment

      • dorinbogdan
        Recognized Expert Contributor
        • Feb 2007
        • 839

        #4
        One solution could be to concatenate the parent & child, so that it results as a single element, then the grouping is easy.
        It would require to build an XSL "concatenat or" which will generate the intermediar XML (haing the parent&child element), and finally build the main XSL to be applied on the intermediar XML.

        Comment

        • jkoufala
          New Member
          • Mar 2007
          • 3

          #5
          i found the solution and wasn't as complicated as that.

          The output from the previous program was sorted by part then parent. This could be done the same way in xslt by using sort.

          The next step was to use the preceding-sibling to locate the previous row
          preceding-sibling::row[position() = 1]/Part
          and
          preceding-sibling::row[position() = 1]/Parent
          to access the previous rows part and parent respectively.

          It was then a simple matter of testing if the previous row to see if had the same parent and part and if so only concatenate the drawing.

          Comment

          • dorinbogdan
            Recognized Expert Contributor
            • Feb 2007
            • 839

            #6
            Good finding.
            I'm glad to hear that you solved it.
            Thanks for information...
            God bless you.

            Comment

            • dorinbogdan
              Recognized Expert Contributor
              • Feb 2007
              • 839

              #7
              Since the problem was solved I will close the thread.

              Comment

              Working...