Altova Mailing List Archives>Archive Index >microsoft.public.xml Archive Home >Recent entries >Thread Prev - Re: xslt and multiple tables >Thread Next - Re: xslt and multiple tables Re: xslt and multiple tablesTo: NULL Date: 1/21/2008 11:50:00 AM
"tshad" <tshad@d...> wrote in message
news:O5EQ0v6UIHA.5208@T......
>
<snip>
I need to add another level of complexity to my xsl and 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
| ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
