This looks like one of those "spot the difference" competitions. In the 30
seconds I allow for looking at questions on this list, I can't spot the
difference between your lookup file and your output file.
Perhaps you should spend a little longer formulating the question.
Michael Kay 
-----Original Message-----
From: Mir Farooq Ali [mailto:mfali(_at_)cs(_dot_)vt(_dot_)edu] 
Sent: 06 June 2004 20:18
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] Lookup table and maintaining hierarchy
I had posted this question a long time, got some responses 
but could not
solve the problem completely.
Consider my XML file that looks like this
<?xml version="1.0" encoding="utf-8" ?>
<TM>
   <T id="something" TC="a">
     <Type>b</Type>
     <Prefs>
       <UC>S</UC>
       <UPS>1</UPS>
     </Prefs>
     <ST>
       <T id="somethinga" TC="a">
         <Type>b</Type>
         <Prefs>
           <UC>S</UC>
           <UPS>1</UPS>
         </Prefs>
         <ST>
           <T id="somethingb" TC="a">
             <Type>b</Type>
             <Prefs>
               <UC>S</UC>
               <UPS>1</UPS>
             </Prefs>
           </T>
           <T id="somethingc" TC="a">
             <Type>b</Type>
             <Prefs>
               <UC>S</UC>
               <UPS>2</UPS>
             </Prefs>
           </T>
         </ST>
       </T>
       <T id="somethingd" TC="a">
         <Type>b</Type>
         <Prefs>
           <UC>S</UC>
           <UPS>2</UPS>
         </Prefs>
       </T>
     </ST>
   </T>
   <T id="somethinge" TC="a">
     <Type>b</Type>
     <Prefs>
       <UC>S</UC>
       <UPS>2</UPS>
     </Prefs>
   </T>
</TM>
With the following lookup file
<AB>
   <TC name="a">
     <TTM type="b">
       <UCM preference="1">
         <UC>S</UC>
         <UPS>
           <pa prefnum="1">
             <XXXX>
               <YYYY />
               <ZZZZ />
             </XXXX>
           </pa>
           <pa prefnum="2">
             <WWWW />
           </pa>
         </UPS>
       </UCM>
     </TTM>
   </TC>
</AB>
The generated output should look something like this
<AB>
   <TC name="a">
     <TTM type="b">
       <UCM preference="1">
         <UC>S</UC>
         <UPS>
           <pa prefnum="1">
             <XXXX>
               <YYYY />
               <ZZZZ />
             </XXXX>
           </pa>
           <pa prefnum="2">
             <WWWW />
           </pa>
         </UPS>
       </UCM>
     </TTM>
   </TC>
</AB>
I am using this stylesheet below
<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                 version="1.0">
<xsl:output indent="yes"/>
<xsl:template match="T">
   <xsl:variable name="tc" select="@TC"/>
   <xsl:variable name="ttm" select="Type"/>
   <xsl:variable name="uc" select="Prefs/UC"/>
   <xsl:variable name="ups" select="Prefs/UPS"/>
   <xsl:for-each select="document('ali-lookup.xml')">
     <xsl:apply-templates mode="modify"
                          select="/AB/TC[(_at_)name=$tc]/TTM[(_at_)type=$ttm]/
                                  
UCM[UC=$uc]/UPS/pa[(_at_)prefnum=$ups]/*"/>
   </xsl:for-each>
</xsl:template>
<xsl:template match="@*|node()">
   <xsl:copy>
     <xsl:apply-templates select="@*|node()"/>
   </xsl:copy>
</xsl:template>
<xsl:template match="*" mode="modify" priority="2">
   <p c="{name(.)}">
     <xsl:apply-templates mode="modify"/>
   </p>
</xsl:template>
<xsl:template match="@*|node()" mode="modify">
   <xsl:copy>
     <xsl:apply-templates select="@*|node()"/>
   </xsl:copy>
</xsl:template>
</xsl:stylesheet>
I am getting this
<?xml version="1.0" encoding="utf-8" ?>
<S>
      <p id="something1" c="XXXX">
              <p id="something11" c="YYYY" />
              <p id="something12" c="ZZZZ" />
      </p>
      <p id="somethinga1" c="XXXX">
              <p id="somethinga11" c="YYYY" />
              <p id="somethinga12" c="ZZZZ" />
      </p>
      <p id="somethingb1" c="XXXX">
              <p id="somethingb11" c="YYYY" />
              <p id="somethingb12" c="ZZZZ" />
      </p>
      <p id="somethingc1" c="WWWW" />
      <p id="somethingd1" c="WWWW" />
      <p id="somethinge1" c="WWWW" />
</S>
where every transformed node is at the same level. I want to preserve
the hierarchy of the original xml file. Any help is appreciated.
Thanks,
-Farooq.
-- 
Mir Farooq Ali
Computer Science, Virginia Tech,
Email: miali(_at_)cs(_dot_)vt(_dot_)edu
Web: http://purl.org/net/farooq
Office: 525 McBryde Hall
Tel: (540) 231-1927 (Office)
--------------------------------------------
(c) 2004 Mir Farooq Ali  All rights reserved
--------------------------------------------
--+------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--+--