I’m looking for some help with XSLT Tranforms.
I’m currently transforming links that match the format:
<link type="button" url="/page.html" text="Do something" />
By using the transform:
<xsl:template match="link">
<a target="_blank" href="{@url}" title="{@text}">
<xsl:if test="@type='button'">
<xsl:attribute name="class">btn</xsl:attribute>
</xsl:if>
<xsl:value-of select="@text" />
</a>
</xsl:template>
Which gives me the output:
<a class="btn" title="Do Something" href="/page.html" target="_blank">Do Something</a>
But now I’m looking to be able to detect when multiple links with the type “button” are grouped together like this:
<link type="button" url="/page.html" text="Do something" />
<link type="button" url="/page.html" text="Do something else" />
And output like so:
<ul class="btns">
<li><a href="page.html" title="Do something" target="_blank" class="btn testing">Do something</a></li>
<li><a href="page.html" title="Do something else" target="_blank" class="btn testing">Do something else</a></li>
</ul>
Can anyone assist on this?
Thanks,
C.
The logic needs to go in the template for the parent of the link elements. Assuming you are using XSLT 2.0 it will be something like this: