Click here to Skip to main content
15,914,066 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,
I am generating html by using xml. My database gives me value as
menuid name parentid IsChecked
1 Hotel null checked
2 Resort 1
3 Swiming Pool 2 checked

i have create xml file like this


XML
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl"
>
  <xsl:output method="xml" indent="yes" encoding="utf-8"/>

  <xsl:template match="/Menus">
    <ul>


      <xsl:call-template name="MenuListing" />
    </ul>
  </xsl:template>
  <!-- Allow for recusive child node processing -->
  <xsl:template name="MenuListing">
    <xsl:apply-templates select="Menu" />
  </xsl:template>

  <xsl:template match="Menu">
    <li>
      <a>
        <!--   Convert Menu child elements to <li> <a> html tags and  add attributes inside <a> tag -->
        <xsl:attribute name="href">
          <xsl:value-of select="url"/>
        </xsl:attribute>
        <xsl:value-of select="name"/>
      </a>
      <input>
        <xsl:attribute name="id">
          <xsl:value-of select="menuid"/>
        </xsl:attribute>
        <xsl:attribute name="type">
          <xsl:text>checkbox</xsl:text>
        </xsl:attribute>
        <xsl:attribute name="class">
          <xsl:text>selectCat</xsl:text>
        </xsl:attribute>
        <xsl:attribute name="checked">
          <xsl:value-of select="IsChecked"/>
        </xsl:attribute>
      </input>


      <!-- Call MenuListing if there are child Menu nodes -->
      <xsl:if test="count(Menu) > 0">
        <ul>
          <xsl:call-template name="MenuListing" />
        </ul>
      </xsl:if>
    </li>
  </xsl:template>
</xsl:stylesheet>




now look into bold part.
I want to add this attribute if the value of IsChecked found as checked else i don't want to add this attribute.
Posted

1 solution

Try this

XML
<xsl:if test="Menu/checked='True'" xmlns:xsl="#unknown">
   <xsl:attribute name="checked">
       <xsl:value-of select="IsChecked" />
   </xsl:attribute>
</xsl:if>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900