I have a menu of a elements all of which get text from xml file using xslt:
<nav>
<xsl:for-each select="package">
<a href="#" onclick="generateContent('{@name}', this);"><xsl:value-of select="@name"/></a>
</xsl:for-each>
</nav>
Now I would like to generate a div (and append it to website when a link would be clicked) with its content generated from my xml file (using xslt like above).
What would be the best way to do it? My guess would be to do it from JS – from generateContent(..) function; but I am unaware if this is even possible and if I wouldn’t be overcomplicating stuff that way.
I think you’re complicating a simple thing. In my way, you should generate all the html contents including menus and sub-items. Then do some javascript stuff to hide and show the sub-items whenever they should be shown. It requires you to use some CSS and javascript (maybe Jquery) things to get your work done.
It’s not a good idea to call the xslt again from the onclick delegate because if you generate all the sub-items again and again, everytime user wants to see them, so you don’t have the state all the time regardless of how hard it can be to implement. However in the way I understand your code it seems impossible (or very hard) to do such a thing.
Hope it helps.
Cheers