Altova Mailing List Archives>Archive Index >microsoft.public.xml Archive Home >Recent entries >Thread Prev - xslt root problem [Thread Next] Re: xslt root problemTo: NULL Date: 1/7/2008 11:26:00 AM
"tshad" <tshad@d...> wrote in message
news:Olf33CWUIHA.4280@T......
>I am having problems with an xml file that has 2 different types of
>structures:
>
> <?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>
> </addresses>
>
> There is addresses/address/tag and address/address/section/tag.
>
> The xlst 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">
> <address>
> <sectionNumber>
> 0
> </sectionNumber>
> <name>
> <xsl:value-of select="@name"/>
> </name>
> <value>
> <xsl:value-of select="."/>
> </value>
> </address>
> </xsl:template>
> <xsl:template match="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>
>
> If my xml had only one or the other types it would work fine. But with
> this one I get 2 roots.
I also tried to change the xpath to put the 2 templates together but got the
same results:
<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>
>
> What do I have to change to give me only one root (dataset) instead of 2?
>
> The resulting xml file is:
>
> <?xml version="1.0" encoding="IBM437"?>
> <dataset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
> <address><sectionNumber>
> 0
> </sectionNumber><name>street</name><value>One
> Microsoft
> Way</value></address>
> </dataset>
> <dataset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
>
>
> <address><sectionNumber>1</sectionNumber><name>street</name><val
> ue>15 Mako Place</value></address>
>
> </dataset>
>
> If you look at it with the indents (not sure why it doesn't indent
> properly as I have indent set to yes. Also you'll notice that the
> sectionNumber that I have hardcoded to 0 indents and the other one
> doesn't.
>
> <?xml version="1.0" encoding="IBM437"?>
> <dataset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
> <address>
> <sectionNumber>
> 0
> </sectionNumber>
> <name>street</name>
> <value>One Microsoft Way</value>
> </address>
> </dataset>
> <dataset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
> <address>
> <sectionNumber>1</sectionNumber>
> <name>street</name>
> <value>15 Mako Place</value>
> </address>
> </dataset>
>
> What I really want it to look like is following (without the second
> dataset).
>
> <?xml version="1.0" encoding="IBM437"?>
> <dataset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
> <address>
> <sectionNumber>
> 0
> </sectionNumber>
> <name>street</name>
> <value>One Microsoft Way</value>
> </address>
> <address>
> <sectionNumber>1</sectionNumber>
> <name>street</name>
> <value>15 Mako Place</value>
> </address>
> </dataset>
>
> Thanks,
>
> Tom
>
| ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
