Hey Friends
I’ve got another xsl/xpath problem. Sure a beginners problem, but I’m thinking still too “imperative”.
<!-- XML -->
<Module>
<WideTeaserElement>
<Headline>Bla bla 1</Headline>
</WideTeaserElement>
<WideTeaserElement>
<Headline>Bla bla 2</Headline>
</WideTeaserElement>
</Module>
<!-- XSL -->
<!-- You are already in the Node Module -->
<xsl:template match="WideTeaserElement">
<ul class="TabbedPanelsTabGroup">
<xsl:for-each select=".">
<li class="TabbedPanelsTab"><a href="#"><xsl:value-of select="pub:Headline"/></a></li>
</xsl:for-each>
</ul>
</xsl>
And what I wanna get as output:
<ul class="TabbedPanelsTabGroup">
<li class="TabbedPanelsTab"><a href="#">Bla bla 1</a></li>
<li class="TabbedPanelsTab"><a href="#">Bla bla 2</a></li>
</ul>
With my XSL I get an output with two <ul> Elements. So my question includes two things:
1) How has to be the transformation for my probleme above?
2) How can you handle loops like for-each in XSL, to have it more “under control”?
You almost never need to use
for-eachin XSL, and if you find yourself using it, you’re probably missing an important bit of XSL’s power.Your case could be much more idiomatically expressed by giving a template for the
HeadLineelement (containing your<li>...</li>element), and then using<xsl:apply-templates/>within the<ul>element within theWideTeaserElementtemplate.