Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


RE: xslt root problem

From: GeraldSheehan@-----------.---------.---
To: NULL
Date: 1/7/2008 12:21:00 PM

Hi Tom,

Change one line from:

<xsl:template match="address">

To:

<xsl:template match="/addresses">

Should do the trick for you!

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 
> 
> 
> 


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent