Altova Mailing List Archives>Archive Index >microsoft.public.xml Archive Home >Recent entries >Thread Prev - Re: xslt root problem >Thread Next - Re: xslt root problem Re: xslt root problemTo: NULL Date: 1/8/2008 7:31:00 AM Hi Tom, The issue with the indents was most likely due to the fact the resulting xml was not well-formed since there were 2 root tags which is illegal in xml. The reason behind the two root tags, is because you're matching "tag" and "address" and applying the templates after the first result, only to do it again on subsequent matches which in turns creates each additional dataset tag. The <xsl:apply-templates> element applies a template to the current element or to the current element's child nodes so you need to be at the parent tag to create the correct output. In your case, the second address tag is created in the xpath location specified. You can actually watch how this result set is created in the XSL Debugger window of XMLSpy. You should check it out and change the xpath values to get a better visual on why this occurs. I hope this helps! -- Best regards, ... Jerry Sheehan ... Pre-Sales Engineer ... Altova, Inc. ... http://www.altova.com "tshad" wrote: > > "Gerald Sheehan" <GeraldSheehan@d...> wrote in message > news:11A0A01F-7FC0-4172-B280-7BABCAC0EB44@m...... > > Hi Tom, > > > > Change one line from: > > > > <xsl:template match="address"> > > > > To: > > > > <xsl:template match="/addresses"> > > > > Should do the trick for you! > > Great. > > Worked perfectly whether I used 2 templates (tag and section/tag) or one > template(tag|section/tag). > > Why was it creating 2 roots in my setup? > > Also, do you know why were the indents not working completely? > > Thanks, > > Tom > > > > > I just checked this in XMLSpy, > > (http://www.altova.com/products/xmlspy/xml_editor.html), and got the > > results > > you're looking for. > > > > -- > > Best regards, > > > > ... Jerry Sheehan > > ... http://www.xmlscoop.com > > > > > > > > > > "tshad" wrote: > > > >> 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. > >> > >> 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 | |||
|
