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/9/2008 9:56:00 PM "tshad" <tfs@d...> wrote in message news:%23lSV32oUIHA.5496@T...... > > "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? > It doesn't. It tries to apply all nodes returned by the select to all of the templates. However only one of the templates will get used and that will be the one which is the best match for the node. If no template matches at all then the builtin default one is used. In your case you would create a new template:- <xsl:template match="analysis"> . . . </xsl:template> -- Anthony Jones - MVP ASP/ASP.NET | ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
