Child nodes need to inherent value from parent - all at same level

Discussion in 'XML' started by johkar, May 27, 2009.

  1. johkar

    johkar Guest

    My problem is that all the nodes that I am concerned about are at the
    same level. The parent nodes are marked below; parent nodes have no
    cov_code value and their childs do have a cov_code value. Essentially
    cov_code without a value serves as a delimiter between groups. In my
    XSLT I am outputting XML and need all the SEQ_NBR nodes of the parent
    an childs to match so:

    Parent1 and children SEQ_NBR 1,1,1

    Parent2 and children SEQ_NBR 2,2,2

    The ONLY thing I can count on is that the Parent;'s SEQ_NBR will
    always be correct and the parent's SEQ_GRP number after the "-" will
    always be 0.


    <myRoot>
    <coverage>
    <cov_supp>
    <cov_code/><!-- PARENTS HAVE NO VALUE-->
    </cov_supp>
    <CommlCoverage>
    <SEQ_GRP>1-0</SEQ_GRP>
    <SEQ_NBR>1</SEQ_NBR><!-- PARENT - THE FIRST PARENT IS 1-->
    </CommlCoverage>
    </coverage>
    <coverage>
    <cov_supp>
    <cov_code>someval</cov_code><!-- CHILDS HAVE A VALUE VALUE-->
    </cov_supp>
    <CommlCoverage>
    <SEQ_GRP>1-1</SEQ_GRP>
    <SEQ_NBR>2</SEQ_NBR><!-- NEED TO OVERRIDE THIS VALUE TO THAT OF ITS
    PARENT-->
    </CommlCoverage>
    </coverage>
    <coverage>
    <cov_supp>
    <cov_code>someval</cov_code>
    </cov_supp>
    <CommlCoverage>
    <SEQ_GRP>1-2</SEQ_GRP>
    <SEQ_NBR>1</SEQ_NBR><!-- NEED TO OVERRIDE THIS VALUE TO THAT OF ITS
    PARENT-->
    </CommlCoverage>
    </coverage>
    <coverage>
    <cov_supp>
    <cov_code/><!-- PARENTS HAVE NO VALUE-->
    </cov_supp>
    <CommlCoverage>
    <SEQ_GRP>2-0</SEQ_GRP>
    <SEQ_NBR>2</SEQ_NBR><!-- PARENT - SECOND PARENT IS 2 AND SO ON-->
    </CommlCoverage>
    </coverage>
    <coverage>
    <cov_supp>
    <cov_code>someval</cov_code>
    </cov_supp>
    <CommlCoverage>
    <SEQ_GRP>2-1</SEQ_GRP>
    <SEQ_NBR>1</SEQ_NBR><!-- NEED TO OVERRIDE THIS VALUE TO THAT OF ITS
    PARENT-->
    </CommlCoverage>
    </coverage>
    <coverage>
    <cov_supp>
    <cov_code>someval</cov_code>
    </cov_supp>
    <CommlCoverage>
    <SEQ_GRP>2-2</SEQ_GRP>
    <SEQ_NBR>2</SEQ_NBR><!-- NEED TO OVERRIDE THIS VALUE TO THAT OF ITS
    PARENT-->
    </CommlCoverage>
    </coverage>
    </myRoot>
     
    johkar, May 27, 2009
    #1
    1. Advertising

  2. Re: Child nodes need to inherent value from parent - all at samelevel

    I'm not sure what you mean by "inherit" in this context. And "parent"
    and "child" are confusing here.

    It sounds like what you really want is: For all coverage elements which
    have a non-empty cov_supp/cov_code, replace their Comm1Coverage/SEQ_NBR
    with the one from the most recent coverage element that _does_ have
    empty cov_supp/cov_code.

    Or, restructuring that into something easier to write as a stylesheet:

    "Copy the document unchanged, EXCEPT: When you see a SEQ_NBR, replace
    its contents with those found on the one whose related cov_code is empty."

    In other words, start with the identity transformation and add something
    like

    <xsl:template match="SEQ_NBR">
    <!-- Replace with "parent's" SEQ_NBR:
    Go up two levels to the containing coverage, look for
    the nearest coverage element (which may be the one which
    contains this SEQ_NBR) whose cov_code
    is empty, take the first one found
    (most recent "parent"), and copy its SEQ_NBR
    subtree unchanged rather than the one we're starting
    from.
    -->
    <xsl:copy-of
    select="/../../
    (self::coverage | preceding-sibling::coverage)
    [not ../../cov_supp/cov_code/node()]
    [1]
    /Comm1Coverage/SEQ_NBR"
    />
    </xsl:template>

    Untested. Could be made more efficient. But it illustrates how to
    approach this sort of problem.

    Better approach is to beat whoever created this document format over the
    head with your favorite W3C Recommendation document until they learn
    that the right approach in XML is to make parents _PARENTS_, not
    siblings. That would tremendously simplify looking up the parent's
    information, yielding better efficiency, more readable documents, more
    readable code, lower cost of maintenance...
     
    Joe Kesselman, May 28, 2009
    #2
    1. Advertising

  3. johkar

    johkar Guest

    Re: Child nodes need to inherent value from parent - all at samelevel

    On May 27, 7:03 pm, Joe Kesselman <>
    wrote:
    > I'm not sure what you mean by "inherit" in this context. And "parent"
    > and "child" are confusing here.
    >
    > It sounds like what you really want is: For all coverage elements which
    > have a non-empty cov_supp/cov_code, replace their Comm1Coverage/SEQ_NBR
    > with the one from the most recent coverage element that _does_ have
    > empty cov_supp/cov_code.
    >
    > Or, restructuring that into something easier to write as a stylesheet:
    >
    > "Copy the document unchanged, EXCEPT: When you see a SEQ_NBR, replace
    > its contents with those found on the one whose related cov_code is empty."
    >
    > In other words, start with the identity transformation and add something
    > like
    >
    > <xsl:template match="SEQ_NBR">
    >         <!-- Replace with "parent's" SEQ_NBR:
    >                 Go up two levels to the containing coverage, look for
    >                 the nearest coverage element (which may be the one which
    >                 contains this SEQ_NBR) whose cov_code
    >                 is empty, take the first one found
    >                 (most recent "parent"), and copy its SEQ_NBR
    >                 subtree unchanged rather than the one we're starting
    >                 from.
    >         -->
    >          <xsl:copy-of
    >              select="/../../
    >                 (self::coverage | preceding-sibling::coverage)
    >                         [not ../../cov_supp/cov_code/node()]
    >                         [1]
    >                 /Comm1Coverage/SEQ_NBR"
    >         />
    > </xsl:template>
    >
    > Untested. Could be made more efficient. But it illustrates how to
    > approach this sort of problem.
    >
    > Better approach is to beat whoever created this document format over the
    > head with your favorite W3C Recommendation document until they learn
    > that the right approach in XML is to make parents _PARENTS_, not
    > siblings. That would tremendously simplify looking up the parent's
    > information, yielding better efficiency, more readable documents, more
    > readable code, lower cost of maintenance...


    Thanks for the reply and yes I agree on the format being whacked.
     
    johkar, May 29, 2009
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. gavnosis
    Replies:
    0
    Views:
    523
    gavnosis
    Aug 2, 2003
  2. Replies:
    1
    Views:
    574
    Soren Kuula
    Aug 24, 2006
  3. Replies:
    1
    Views:
    1,207
    Joe Kesselman
    Nov 1, 2006
  4. Noel Dolan
    Replies:
    0
    Views:
    236
    Noel Dolan
    Jul 18, 2004
  5. Bitswapper
    Replies:
    5
    Views:
    148
    Prasad, Ramit
    Aug 27, 2013
Loading...

Share This Page