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 tablesTo: NULL Date: 1/21/2008 9:47:00 PM
"tshad" <tshad@d...> wrote in message
news:OC$t9aGXIHA.5208@T......
>
> "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>
I was able to get this to almost work:
<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"/>
<xsl:apply-templates select="names"/>
</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:template match="name">
<name>
<first>
<xsl:value-of select="first"/>
</first>
<last>
<xsl:value-of select="last"/>
</last>
</name>
</xsl:template>
</xsl:stylesheet>
But I end up with:
<?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 MicrosoftWay</value>
</address>
<address>
<sectionNumber>1</sectionNumber>
<name>street</name>
<flag xsi:nil="true"></flag>
<unit xsi:nil="true"></unit>
<value>15 Mako Place</value>
</address>
<analysis>
<form>text</form>
<value>09282007</value>
<name>March Errors</name>
</analysis>
</dataset>
<name xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<first>Tom</first>
<last>Smith</last>
</name>
<name xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<first>Larry</first>
<last>Jones</last>
</name>
It looks like I have 2 roots here.
What I want is the <dataset> be the root and <address>,<analysis> and <name>
all be on the same level. This would mean that my dataset would create 3
tables (address, analysis and name).
How would I change this to accomplish that?
Thanks,
Tom
| ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
