Hi
Im really tired of trying to make my XML document well-formed as well 
as enable recursive looping until no more 'children' or 'implications' 
of a particular element are found, so would appreciate any help. The 
output that I receive is correct (it does all the right extraction) though.
My output XML file (after XSLT processing) is of the form
----------------
<Top>
  <PrimeConcept id="0001" type="none">A</PrimeConcept>
  <SubConcepts>
     <SubConcept id="0002" name="A1">
       <Value ref="0003">hasProperty1 AB</Value>
       <Value ref="0004">hasProperty2 XY</Value>
       <SubConcept id="0004" name="XY">
           <ChildConcept ref="0005">XY1</ChildConcept>
           <SubConcept id="0005" name="XY1">
              <ChildConcept ref="0007">XY11</ChildConcept>
              <ChildConcept ref="0008">XY12</ChildConcept>
           </SubConcept>
           <ChildConcept ref="0006">XY2</ChildConcept>
        </SubConcept>
   </SubConcept>
  </SubConcepts>
</Top>
----------------
As you can see its an utterly loopy XML doc with <SubConcept> inside 
<SubConcept>. One of the reasons for this is the recursive call to a 
template until no other 'children' or 'imply' conditions are found. My 
XSL template blocks are such:
--------------
<xsl:template match="DEFCONCEPT">
    <xsl:if test="@name = $prime">
        <PrimeConcept id="{@id}" type="none">
            <xsl:value-of select="@name"/>
        </PrimeConcept>
       
       <xsl:if test="following-sibling::DEFCONCEPT[@name = $constraint] 
| preceding-sibling::DEFCONCEPT[@name=$constraint]">
           <xsl:for-each select="following-sibling::DEFCONCEPT[@name = 
$constraint] | preceding-sibling::DEFCONCEPT[@name=$constraint]">
               <SubConcepts>
                   <SubConcept id="{@id}" name="{@name}">
                       <xsl:if test="IMPLIES/SOME | IMPLIES/ALL">
                           <xsl:for-each select="IMPLIES/SOME | 
IMPLIES/ALL">
                               <Value type="TEXT" 
ref="{CONCEPT/@ref}"><xsl:value-of 
select="(OBJECT-SLOT|self::*[not(OBJECT-SLOT)]/DATA-SLOT)/@name"/> <xsl:value-of 
select="CONCEPT/@name"/></Value>
                               <xsl:call-template 
name="impliedRestrictions">
                                   <xsl:with-param name="conceptRef" 
select="CONCEPT/@ref"/>
                               </xsl:call-template>
                           </xsl:for-each>
                       </xsl:if>
                   </SubConcept>
               </SubConcepts>
           </xsl:for-each>
       </xsl:if>
   </xsl:if>   
</xsl:template>
<xsl:template name="impliedRestrictions">
  
   <xsl:param name="conceptRef"/>
   <xsl:for-each select="following::DEFCONCEPT[@id=$conceptRef] | 
preceding::DEFCONCEPT[@id=$conceptRef]">
       <xsl:if test="IMPLIES/SOME | IMPLIES/ALL | CHILD">
           <SubConcept id="{@id}" name="{@name}">
               <xsl:if test="CHILD">
                   <xsl:for-each select="CHILD/CONCEPT">
                       <ChildConcept ref="{@ref}"><xsl:value-of 
select="@name"/></ChildConcept>
                       <xsl:call-template name="impliedRestrictions">
                           <xsl:with-param name="conceptRef" 
select="@ref"/>
                       </xsl:call-template>
                   </xsl:for-each>
               </xsl:if>
               <xsl:if test="IMPLIES/SOME | IMPLIES/ALL">
                   <xsl:for-each select="IMPLIES/SOME | IMPLIES/ALL">
                       <Value type="TEXT" 
ref="{CONCEPT/@ref}"><xsl:value-of 
select="OBJECT-SLOT/@name"/> <xsl:value-of 
select="CONCEPT/@name"/></Value>
                       <xsl:call-template name="impliedRestrictions">
                           <xsl:with-param name="conceptRef" 
select="CONCEPT/@ref"/>
                       </xsl:call-template>
                   </xsl:for-each>
               </xsl:if>
           </SubConcept>
       </xsl:if>       
   </xsl:for-each>
</xsl:template>
--------------
Could someone please help me in trying to obtain an output of the form
----------------
<Top>
  <PrimeConcept id="0001" type="none">A</PrimeConcept>
  <SubConcepts>
     <SubConcept id="0002" name="A1">
       <Value ref="0003">hasProperty1 AB</Value>
       <Value ref="0004">hasProperty2 XY</Value>
   </SubConcept>
   <SubConcept id="0004" name="XY">
           <ChildConcept ref="0005">XY1</ChildConcept>
           <ChildConcept ref="0006">XY2</ChildConcept>
    </SubConcept>
      <SubConcept id="0005" name="XY1">
              <ChildConcept ref="0007">XY11</ChildConcept>
              <ChildConcept ref="0008">XY12</ChildConcept>
     </SubConcept>
  </SubConcepts>
</Top>
---------------
Would truly appreciate any help.
Thanks
Rahil