Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: xslt and multiple tables

From: "tshad" <tfs@----------.--->
To: NULL
Date: 1/8/2008 11:03:00 PM


"Anthony Jones" <Ant@y...> wrote in message 
news:u3BzqjeUIHA.5836@T......
> "tshad" <tfs@d...> wrote in message
> news:uFuhAIbUIHA.5404@T......
>> I have an xml file and xslt file that worked fine together until I added
>> another set of tags (analysis).
>>
>> <?xml version="1.0"?>
>> <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>09282007</version>
>>                       <name>March Errors</name>
>>                </rulefile>
>>           </files>
>>      </analysis>
>> </addresses>
>>
>> The xslt file is:
>>
>> <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="address">
>>        <dataset>
>>            <xsl:apply-templates/>
>>        </dataset>
>>    </xsl:template>
>>  <xsl:template match="tag|section/tag">
>>        <address>
>>           <sectionNumber>
>>                <xsl:value-of select="ancestor::section/@Comp"/>
>>          </sectionNumber>
>>           <name>
>>                 <xsl:value-of select="@name"/>
>>             </name>
>>             <value>
>>                 <xsl:value-of select="."/>
>>             </value>
>>        </address>
>>  </xsl:template>
>> </xsl:stylesheet>
>>
>> But the result file is:
>>
>> <?xml version="1.0" encoding="IBM437"?>
>> <dataset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
>>
>>
> <address><sectionNumber></sectionNumber><name>street</name><flag
>>  xsi:nil="true"></flag><unit xsi:nil="true"></unit><value>One Microsoft
>> Way</val
>> ue></address>
>>
>>
>>
>>
> <address><sectionNumber>1</sectionNumber><name>street</name><fla
>> g xsi:nil="true"></flag><unit xsi:nil="true"></unit><value>15 Mako
>> Place</value>
>> </address>
>>
>>
>>
>>
>>
>>                                 09282007
>>                                 March Errors
>>
>>
>>
>> </dataset>
>>
>> Not sure why I have all the blank lines but you will notice that all the
>> tags after the 2nd "address" are gone.
>>
>> There are no tags around the "09282007" and "March Errors".
>>
>> What I am trying to do is set this up so that I will end up with 2 tables
> in
>> a dataset that will read this result - an "address" table and an
> "analysis"
>> table.
>>
>> How would I change my xlst file to do this?
>>
>
> Try this:-
>
>    <xsl:template match="/addresses">
>        <dataset>
>            <xsl:apply-templates select="address" />
>        </dataset>
>    </xsl:template>
>
> Its usually a good idea to make sure your first template matches the
> document root element and if possible use an explicit select on
> apply-templates.
>

That works but just drops the analysis section (although it does get rid of 
the text from that section that was being displayed.  What I was using was:

<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"/>
       </dataset>
   </xsl:template>
 <xsl:template match="tag|section/tag">
       <address>
          <sectionNumber>
               <xsl:value-of select="ancestor::section/@Comp"/>
         </sectionNumber>
          <name>
                <xsl:value-of select="@name"/>
            </name>
            <value>
                <xsl:value-of select="."/>
            </value>
       </address>
 </xsl:template>
</xsl:stylesheet>


I assume that if I want to use the analysis section I would need to do 
something like:

       <dataset>
           <xsl:apply-templates select="address"/>
            <xsl:apply-templates select="analysis"/>
       </dataset>

Then I would need to set up some type of match for the analysis section but 
how does the xsl know which match to use with which select?

Thanks,

Tom
> -- 
> Anthony Jones - MVP ASP/ASP.NET
>
> 




transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent