Ureader.com  
Microsoft software help and Community
   home   |   control panel login   |   archive   |  
 
XML
data.xmlanalysis
mappoint.webservice
msf
msxml-webrelease
netmyservices.sdk
passport.sdk
soap
soapsdk
uddi.general
uddi.programming
uddi.specification
xml
xmlsqlwebrelease
xsl
  
 
date: Tue, 22 Jan 2008 18:57:41 -0800,    group: microsoft.public.xsl        back       


transformation not work with 2 sets of node same level   
I have a test xml file that is similar in structure to the file I am 
actually going to use but is much simpler

I had built this before only wanting 2 tables.  But I needed to add another 
set of nodes that were the same level as my other outside nodes and I can't 
seem to get it to work.

What I want to end up with is a file that my dataset will read as 3 tables.
At the moment I have only 2 tables (address and Analysis).  I added a new
table (name).  when I added the new <names> section, the transformation
works fine except there are no tags around the names (which makes sense
since I haven't set up any templates for them).  When I do I get errors
because <names> is on the same level as <addresses>, so I need a different
type of  match section, but I can't make it work.

The tables would give me something like:

<address><sectionNumber>....</sectionNumber></address>
<analysis><form>...</form></analysis

I need it to look something like:
<data>
    <address><sectionNumber>....</sectionNumber></address>
    <analysis><form>...</form></analysis>
    <name><first></first><last></last></name>
</data>

How would I change the following xslt file to accomplish that?

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="addresses">
   <dataset>
       <xsl:apply-templates select="address"/>
       <xsl:apply-templates select="analysis"/>
   </dataset>
</xsl:template>
<xsl:template match="tag">
   <address>
       <sectionNumber>
            <xsl:value-of select="ancestor::section/@Comp"/>
       </sectionNumber>
       <name>
            <xsl:value-of select="@name"/>
       </name>
       <flag>
           <xsl:if test="not(@flag)">
               <xsl:attribute name="xsi:nil">true</xsl:attribute>
           </xsl:if>
          <xsl:value-of select="@flag"/>
       </flag>
      <unit>
           <xsl:if test="not(@unit)">
               <xsl:attribute name="xsi:nil">true</xsl:attribute>
          </xsl:if>
         <xsl:value-of select="@unit"/>
      </unit>
     <value>
         <xsl:value-of select="."/>
     </value>
   </address>
</xsl:template>
<xsl:template match="files/rulefile">
     <analysis>
         <form>
               <xsl:value-of select="version/@form"/>
         </form>
        <value>
             <xsl:value-of select="version"/>
       </value>
       <name>
           <xsl:value-of select="name"/>
       </name>
   </analysis>
</xsl:template>
</xsl:stylesheet>


I tried sticking something like:

<xsl:template match="names">
   <dataset>
       <xsl:apply-templates select="name"/>
   </dataset>
</xsl:template>

But that didn't work

The new xml file looks like:

<?xml version="1.0"?>
<data>
     <addresses>
         <address>
             <tag name="street">One Microsoft Way</tag>
         </address>
         <address>
              <section Comp="1">
                  <tag name="street">15 Mako Place</tag>
             </section>
         </address>
        <analysis >
            <files>
                <rulefile>
                     <version form="text">09282007</version>
                     <name>March Errors</name>
               </rulefile>
           </files>
        </analysis>
     </addresses>
    <names>
          <name>
                <first>Tom</first>
                <last>Smith</last>
         </name>
        <name>
            <first>Larry</first>
            <last>Jones</last>
        </name>
    </names>
</data>

Thanks,

Tom
date: Tue, 22 Jan 2008 18:57:41 -0800   author:   tshad

Google
 
Web ureader.com


    COPYRIGHT 2007, YARDI TECHNOLOGY LIMITED, ALL RIGHT RESERVE  |   contact us