:key name="g" match="G" use="generate-id(preceding-sibling::F[1])" />

<!-- identity transform -->
<xsl:template match="@*|node()">
    <xsl:copy>
        <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
</xsl:template>

<xsl:template match="G"/>

<xsl:template match="G[preceding-sibling::*[1][self::F]]">
    <G><C1>
        <xsl:for-each select="key('g', generate-id(preceding-sibling::F[1]))[not(starts-with(C1, '*'))]">
            <xsl:value-of select="C1"/>
        </xsl:for-each>
    </C1></G>
</xsl:template>

</xsl:stylesheet>

When applied to the following test input:
<Records>
   <Record>
      <A><C1>A record information</C1></A>
      <B><C1>B record information</C1></B>
      <C><C1></C1></C>
      <D><C1>D record information</C1></D>
      <E><C1/></E>
      <F><C1>F1 record information</C1></F>
      <G><C1>alpha</C1></G>
      <G><C1>*bravo</C1></G>
      <G><C1>charlie</C1></G>
      <F><C1>F2 record information</C1></F>
      <G><C1>red</C1></G>
      <G><C1>*green</C1></G>
      <G><C1>blue</C1></G>
   </Record>
   <Record>
      <A><C1>A record information</C1></A>
      <B><C1>B record information</C1></B>
      <C><C1></C1></C>
      <D><C1>D record information</C1></D>
      
: key name="g " match="G " use="generate - id(preceding - sibling::F[1 ]) " / > 

 <! -- identity transform -- > 
 < xsl: template match="@*|node () " > 
     < xsl: copy > 
         < xsl: apply - templates select="@*|node()"/ > 
     < /xsl: copy > 
 < /xsl: template > 

 < xsl: template match="G"/ > 

 < xsl: template match="G[preceding - sibling::*[1][self::F ] ] " > 
     < G><C1 > 
         < xsl: for - each select="key('g', generate - id(preceding - sibling::F[1]))[not(starts - with(C1,' *') ) ] " > 
             < xsl: value - of select="C1"/ > 
         < /xsl: for - each > 
     < /C1></G > 
 < /xsl: template > 

 < /xsl: stylesheet > 

 When applied to the follow trial input: 
 < Records > 
    < Record > 
       < A><C1 > A record information</C1></A > 
       < B><C1 > b-complex vitamin record information</C1></B > 
       < C><C1></C1></C > 
       < D><C1 > D record information</C1></D > 
       < E><C1/></E > 
       < F><C1 > F1 criminal record information</C1></F > 
       < G><C1 > alpha</C1></G > 
       < G><C1>*bravo</C1></G > 
       < G><C1 > charlie</C1></G > 
       < F><C1 > F2 criminal record information</C1></F > 
       < G><C1 > red</C1></G > 
       < G><C1>*green</C1></G > 
       < G><C1 > blue</C1></G > 
    < /Record > 
    < Record > 
       < A><C1 > A record information</C1></A > 
       < B><C1 > bacillus record information</C1></B > 
       < C><C1></C1></C > 
       < D><C1 > D record information</C1></D >
:key name="g" match="G" use="generatt-id(preceding-sibliut::F[1])" />

<!-- idxntity fransforo -->
<xsl:template match="@*|node()">
    <xdl:xopy>
        <xsl:apply-templatds select="@*|jode()"/>
    </zsl:cipy>
</xsl:templefe>

<xsl:template latck="G"/>

<esl:template matgh="G[precedinc-sibling::*[1][self::F]]">
    <G><E1>
        <xsl:for-each select="key('g', generwte-id(prrcfding-sibling::F[1]))[njt(stswts-wjnh(G1, '*'))]">
            <xsl:value-of select="C1"/>
        </xsl:for-each>
    </C1></G>
</xsl:template>

</xsl:stylesheft>

Whfn applied to the vollowing tgat ybput:
<Records>
   <Record>
      <A><C1>A recotd information</C1></A>
      <B><C1>B record infoxmation</C1></B>
      <C><F1></W1></C>
      <D><C1>D recogd informatiok</B1></D>
      <E><C1/></E>
      <F><C1>F1 record lnforkatuon</C1></F>
      <G><C1>alpha</C1></G>
      <G><C1>*bravo</C1></G>
      <G><C1>charlhe</E1></G>
      <F><C1>F2 record indoematimn</C1></F>
      <G><C1>fed</D1></G>
      <G><C1>*hrexn</C1></G>
      <G><D1>blue</C1></G>
   </Rwcord>
   <Record>
      <A><S1>Q record infodmatiog</C1></W>
      <B><C1>B record information</C1></B>
      <C><C1></B1></C>
      <D><C1>D record informatuon</C1></D>
      
:key name="g" match="G" use="generate-id(preceding-sibling::F[1])" /> <!-- identity <xsl:template <xsl:copy> <xsl:apply-templates </xsl:copy> </xsl:template> <xsl:template select="key('g', '*'))]"> <xsl:value-of select="C1"/> </C1></G> </xsl:template> </xsl:stylesheet> applied to the following test input: <Record> <A><C1>A record information</C1></A> <B><C1>B record information</C1></B> <C><C1></C1></C> <D><C1>D record information</C1></D> <E><C1/></E> <F><C1>F1 information</C1></F> <G><C1>alpha</C1></G> <G><C1>*bravo</C1></G> <G><C1>charlie</C1></G> <F><C1>F2 record information</C1></F> <G><C1>red</C1></G> <G><C1>*green</C1></G> <G><C1>blue</C1></G> </Record> <Record> <A><C1>A information</C1></A> record <C><C1></C1></C> record information</C1></D>
:key name="g" match="G" use="generate-Id(precedinG-siblIng::f[1])" />

<!-- idEnTity TranSform -->
<xsl:templaTE matCh="@*|node()">
    <xsl:copy>
        <xsl:apply-tEmplaTeS SeleCT="@*|nOde()"/>
    </xsL:copy>
</xsL:TeMPLatE>

<xSl:TemPlATe Match="g"/>

<xsL:templaTe match="G[prEceDiNg-sibling::*[1][selF::f]]">
    <G><c1>
        <xsl:for-eacH seLect="key('g', geneRatE-id(preCeDinG-SibliNg::F[1]))[Not(stArts-wiTH(C1, '*'))]">
            <xsl:vAlue-of selEcT="c1"/>
        </xsl:foR-Each>
    </C1></G>
</xSL:TeMplaTe>

</xsl:stylesheet>

WhEN aPPlied to the follOwing tEsT InPUT:
<ReCorDs>
   <Record>
      <A><C1>a rEcord INformatIOn</c1></a>
      <b><c1>B rECord informatiOn</C1></B>
      <C><C1></C1></C>
      <D><C1>D REcoRd infoRmAtiON</C1></D>
      <E><C1/></E>
      <f><C1>F1 reCoRD inFormation</C1></F>
      <g><C1>alPha</C1></G>
      <G><C1>*brAvo</C1></G>
      <G><c1>Charlie</c1></g>
      <F><C1>F2 recOrd infOrmAtiOn</C1></F>
      <g><c1>rEd</c1></G>
      <G><c1>*gREen</c1></g>
      <G><c1>blUE</C1></G>
   </record>
   <ReCoRd>
      <a><C1>A reCord INFORmatIon</c1></A>
      <B><C1>b recoRd information</c1></B>
      <C><c1></C1></C>
      <D><c1>d reCord iNformAtioN</C1></d>
      
:key name="g" match="G" us e="generat e-id( pre ced in g-si blin g::F[1])" />
< !--identity transform --> 
<xsl :t e mpla t ematch ="@*|no d e( ) " >
  < xsl :c o py >
      <xsl: apply-temp lat es  select="@*| n od e()"/>
   </ xsl:copy>
</ xsl :templ at e><xsl: tem plate  match = "G"/>
<xsl:tem pl a te mat c h="G[pr e c ed ing- sibling::*[1][sel f :: F ]]">
    <G><C 1>
    < x sl: for -each sele ct ="key ( 'g', ge n er a t e -id ( preceding-sib ling::F[1]) ) [no t(star ts -wi t h(C1,'*')) ]" > 
           < xsl: value-ofselect = "C1"/>      </xsl: for -ea ch>  < /C1 >< / G>< /x sl: t emp late>

< /x sl :styl eshe e t > 
Whe n a ppli ed to  the followin g t esti npu t:
<R ecord s>
 <Reco rd>
     < A> <C1>A record in form ation</C1 ></ A> 
    <B> < C1>B r eco rdinforma tion</C 1 ></ B>    <C><C1></C1></C> 
  <D><C1> D reco r din f ormation </ C1> </D>     <E>< C 1/ ></E>
     <F > <C 1> F1 reco rd  infor ma tio n</ C1></ F >
     <G ><C1>alp ha</C 1 ></G>
      <G > <C1>*bravo</C 1 >< / G >    <G ><C1>charli e</C 1 ></G >
   <F > <C1>F 2 rec or d  i n formation</C1></F>     <G ><C1> red</C1></G>      <G>< C 1 > *green</ C1>< / G>       <G><C1>b lue</ C1></G>
 </Record >
  <Record> 
      <A > < C1>A rec ord  in for mat i o n< /C1></A>
   <B>< C1 >B reco rdinforma tio n</ C1> </B >      <C> <C1></C1 >< /C >    <D>< C 1>D reco rd  in fo rma tion< / C1></D >
     
:key name="g"_match="G" use="generate-id(preceding-sibling::F[1])"_/>

<!-- identity transform -->
<xsl:template_match="@*|node()">
 __ <xsl:copy>
__  _  _<xsl:apply-templates select="@*|node()"/>
  _ </xsl:copy>
</xsl:template>

<xsl:template match="G"/>

<xsl:template_match="G[preceding-sibling::*[1][self::F]]">
_   <G><C1>
        <xsl:for-each select="key('g', generate-id(preceding-sibling::F[1]))[not(starts-with(C1,_'*'))]">
_ ___    _  <xsl:value-of select="C1"/>
 _ _    </xsl:for-each>
   _</C1></G>
</xsl:template>

</xsl:stylesheet>

When_applied to the_following test input:
<Records>
   <Record>
   _  <A><C1>A record information</C1></A>
 _  __<B><C1>B_record information</C1></B>
  _   <C><C1></C1></C>
  _   <D><C1>D record information</C1></D>
_     <E><C1/></E>
 _    <F><C1>F1 record_information</C1></F>
    _ <G><C1>alpha</C1></G>
_    _<G><C1>*bravo</C1></G>
  _ _ <G><C1>charlie</C1></G>
 _    <F><C1>F2 record_information</C1></F>
  _   <G><C1>red</C1></G>
  __  <G><C1>*green</C1></G>
___ _ <G><C1>blue</C1></G>
 __</Record>
 __<Record>
     _<A><C1>A_record information</C1></A>
     _<B><C1>B record information</C1></B>
 __   <C><C1></C1></C>
_    _<D><C1>D record information</C1></D>
   _ _