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/7/2008 1:03:00 PM "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 | |||
|
