ofortuna
ofortuna

Reputation: 187

dynamic HREF attribute by XSLT

Can anyone plese advice how I can have dynamic HREF attribute in the place of ʜᴛᴛᴘ://abc.com by XSLT in following code snippet?

<xsl:for-each select="MenuItems/mainmenu">
    <a href="ʜᴛᴛᴘ://abc.com">
       <span><xsl:value-of select="menuName"/></span>
    </a>   
</xsl:for-each>

sample xml

<MenuItems>
<mainmenu>
    <menuID>1</menuID>
    <menuName>Home</menuName>
    <menuLink>http://aaa.com</menuLink>
        <subMenuList>
            <menuID>2</menuID>
            <menuName>Home</menuName>
            <menuLink>http://a1.com</menuLink>
        </subMenuList>
        <subMenuList>
            <menuID>3</menuID>
            <menuName>List of RCCs</menuName>
            <menuLink>http://a2.com</menuLink>
        </subMenuList>
        <subMenuList>
        <menuID>4</menuID>
        <menuName>Turnover Workout</menuName>
        <menuLink>http://a3.com</menuLink>
        </subMenuList>
</mainmenu>
<MenuItems>

Upvotes: 1

Views: 5065

Answers (2)

Michael Kay
Michael Kay

Reputation: 163262

Use an attribute value template:

<a href="{menuLink}">
  <span><xsl:value-of select="menuName"/></span>
</a> 

Upvotes: 1

O. R. Mapper
O. R. Mapper

Reputation: 20710

If I understand correctly, you are looking for the <xsl:attribute> element:

<a>
    <xsl:attribute name="href"><xsl:value-of select="menuLink"/></xsl:attribute>
    <span><xsl:value-of select="menuName"/></span>
</a>

Upvotes: 3

Related Questions