Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: Recurse

From: krsherm@-----------.---------.---
To: NULL
Date: 6/1/2005 11:22:00 AM
N - 

Thank you so much! Your transform worked perfectly... the best part is that 
I actually understand it! Thanks again... 

Kevin

"N. Demos" wrote:

> Kevin wrote:
> > <<PlainText>>
> > 
> > Hello all. I am somewhat new to XSL transforms. I have an xml document that 
> > represents a sitemap (or, it will... this is just test data). I want to 
> > display the sitemap in Microsoft TreeView control as mentioned in this 
> > article (http://aspnet.4guysfromrolla.com/articles/051403-1.aspx).
> > 
> > The raw xml file could have any number of nestings... here is a sample...
> > 
> > <sitemap en="Home" es="Pagina Principal" url="/default.aspx">
> >  <page en="Personal Finance" es="Finanzas Personales" url="/pf/default.aspx" 
> > />
> >  <page en="Community" url="/community/default.aspx">
> >   <page en="Community Champions" url="/community/champions.aspx">
> >    <regionalization region="2" en="Community in English!" />
> >   </page>
> >  </page>
> >  <page en="About Us" url="/au/defualt.aspx" />
> >  <page en="Contact Us" url="/cu/default.aspx">
> >   <page en="Phone Directory" url="cu/PhoneDirectory.aspx">
> >    <page en="President" url="/cu/President.aspx">
> >     <page en="President's Message" url="/cu/President/message.aspx" />
> >    </page>
> >    <page en="Vice-President" url="/cu/vicepresident.aspx" />
> >    <page en="Vice-President Sales" url="/cu/vpsales.aspx" />
> >   </page>
> >  </page>
> >  <page en="Investors" url="in/default.aspx">
> >   <page en="Annual Reports" url="/in/ar.aspx" />
> >  </page>
> > </sitemap>
> > 
> > This xml file shows four levels deep. Microsoft's treeview control requires 
> > the input xml file to be in <TREENODES><treenode/></TREENODES> format... so 
> > the above file SHOULD be transformed to:
> > 
> > Please help me understand how to re-write the stylesheet so that the raw xml 
> > input file can have any number of nesting possible. Thank you in advance....
> > 
> > Regards,
> > 
> > Kevin 
> > 
> > 
> Kevin,
> Try the stylesheet below. Since you are replicating the structure of the 
> original XML, you only need two templates: one for the root <sitemap>, 
> and one for each <page> node. As you can see below, the <page> template 
> recursively applies itself, <xsl:apply-templates select="page" />. If no 
> child <page> node is found then nothing is generated.
> 
> The code to assign the value of the 'en' attribute to text attribute, 
> text="{@en}" uses the shorthand 'value-of' operator, '{}' (curly 
> brackets). The longer way to do this is
> 
> <treenode>
>    <xsl:attribute name="text" select="@en" />
>    <xsl:apply-templates select="page" />
> </treenode>
> 
> Note that when using this method (the long one) that all attribute tags 
> must occur immediatly following the opening tag of the element they are 
> being assigned to, and before the assignment of any child nodes or text.
> 
> HTH
> 
> Regards,
> N. Demos
> 
> XSL:
> -------------------
> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
> version="1.0">
> <xsl:output method="xml" version="1.0" indent="yes"/>
> 
> <xsl:template match="/sitemap">
>    <TREENODES>
>      <xsl:apply-templates select="page" />
>    </TREENODES>
> </xsl:template>
> 
> <xsl:template match="page">
>    <treenode text="{@en}">
>      <!-- Recursive Call -->
>      <xsl:apply-templates select="page" />
>    </treenode>
> </xsl:template>
> 
> </xsl:stylesheet>
> 
> -- 
> Change "seven" to a digit to email me.
> 


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