Hi I am looking for an XSLT for generating HTML as shown below.
Following are the details of the transformations.
Please provide your inputs.
For each PageGroup I need to create an
In HTML an Li element should be populated.
<li>
<a>Test</a>
</li>
And under each Pagegroup for every Page Ul should be populated.
<ul>
<li>
<a>Test Role 1</a>
</li>
<li>
<a>Test Role 2</a>
</li>
</ul>
XML:
<menuitems>
<pagegroup title="Test">
<pages id="1" url="Test1.aspx" description="Tes 1" type="1" role="Test Role 1"/>
<pages id="2" url="Test2.aspx" description="Tes 2" type="1" role="Test Role 2"/>
<pagegroup title="Projects">
<pages id="4" url="Test 2 3.aspx" description="Test 2 3" type="1" role="Rol 3"/>
<pages id="4" url="Test 2 5.aspx" description="Test 2 5" type="1" role="Rol 4"/>
</pagegroup>
</pagegroup>
</menuitems>
Output HTML expecting
<ul>
<li>
<a>Test</a>
</li>
<ul>
<li>
<a>Test Role 1</a>
</li>
<li>
<a>Test Role 2</a>
</li>
<ul>
<li>
<a>Projects</a>
</li>
<ul>
<li>
<a>Test 2 3</a>
</li>
<li>
<a>Test 2 5</a>
</li>
</ul>
</ul>
</ul>
</ul>
XSLT Tried
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="pagegroup">
<ul>
<xsl:apply-templates select="pages"/>
<li>
<xsl:value-of select="@title"/>
</li>
</ul>
</xsl:template>
<xsl:template match="pages">
<li>
<xsl:value-of select="@role"/>
<xsl:if test="pagegroup">
<ul>
<xsl:apply-templates select="pages"/>
<li>
<xsl:value-of select="@title" />
</li>
</ul>
</xsl:if>
</li>
</xsl:template>
</xsl:stylesheet>
You are not too far off. The main issue is that in your template to match pagegroup you are doing this…
When really you want to be doing this, to match both pages and pagegroups
Try the following XSLT
When applied to your XML, the following is output