sourabh choubey

sourabh choubey

  • NA
  • 174
  • 46.2k

Nested foreachloop not working in XSLT

Jul 28 2016 2:06 AM
MY XML.. 
<?xml version="1.0" encoding="utf-8"?>
<BlogCategories>
<BlogCategory ID="1" ParentID="0" Name="Travel" Active="1" seo_keywords="Travel Blogs" seo_description="Travel Blogs" ParentName=""/>
<BlogCategory ID="2" ParentID="0" Name="HealthCare" Active="1" seo_keywords="HealthCare Blogs" seo_description="HealthCare Blogs" ParentName=""/>
<BlogCategory ID="3" ParentID="0" Name="Realestate" Active="1" seo_keywords="Realestate" seo_description="Realestate " ParentName=""/>
<BlogCategory ID="4" ParentID="0" Name="Technology" Active="1" seo_keywords="Technology" seo_description="Technology" ParentName=""/>
<BlogCategory ID="5" ParentID="0" Name="Entertainment " Active="1" seo_keywords="Entertainment " seo_description="Entertainment " ParentName=""/>
<BlogCategory ID="6" ParentID="0" Name="LifeStyle" Active="1" seo_keywords="LifeStyle" seo_description="LifeStyle" ParentName=""/>
<BlogCategory ID="7" ParentID="0" Name="Electronics " Active="1" seo_keywords="Electronics" seo_description="Electronics" ParentName=""/>
<BlogCategory ID="8" ParentID="0" Name="Education" Active="1" seo_keywords="Education" seo_description="Education" ParentName=""/>
<BlogCategory ID="9" ParentID="0" Name="Business " Active="1" seo_keywords="Business " seo_description="Business " ParentName=""/>
<BlogCategory ID="10" ParentID="0" Name="Sports" Active="1" seo_keywords="Sports" seo_description="Sports" ParentName=""/>
<BlogCategory ID="11" ParentID="0" Name="Auto " Active="1" seo_keywords="Auto " seo_description="Auto " ParentName=""/>
<BlogCategory ID="12" ParentID="0" Name="Jobs" Active="1" seo_keywords="Jobs" seo_description="Jobs" ParentName=""/>
<BlogCategory ID="13" ParentID="1" Name="Destinations" Active="1" seo_keywords="Destinations" seo_description="Destinations" ParentName="Travel"/>
<BlogCategory ID="14" ParentID="1" Name="Stories " Active="1" seo_keywords="Stories " seo_description="Stories " ParentName="Travel"/>
<BlogCategory ID="15" ParentID="1" Name="Adventure" Active="1" seo_keywords="Adventure" seo_description="Adventure" ParentName="Travel"/>
<BlogCategory ID="16" ParentID="1" Name="WildLife" Active="1" seo_keywords="WildLife" seo_description="WildLife" ParentName="Travel"/>
<BlogCategory ID="17" ParentID="1" Name="Videos" Active="1" seo_keywords="Videos" seo_description="Videos" ParentName="Travel"/>
<BlogCategory ID="18" ParentID="2" Name="Food" Active="1" seo_keywords="Food" seo_description="Food" ParentName="HealthCare "/>
<BlogCategory ID="19" ParentID="2" Name="Yoga" Active="1" seo_keywords="Yoga" seo_description="Yoga" ParentName="HealthCare "/>
<BlogCategory ID="20" ParentID="2" Name="Medical" Active="1" seo_keywords="Medical" seo_description="Medical" ParentName="HealthCare "/>
<BlogCategory ID="21" ParentID="2" Name="Fitness" Active="1" seo_keywords="Fitness" seo_description="Fitness" ParentName="HealthCare "/>
<BlogCategory ID="22" ParentID="2" Name="Beauty" Active="1" seo_keywords="Beauty" seo_description="Beauty" ParentName="HealthCare "/>
<BlogCategory ID="23" ParentID="3" Name="Residential" Active="1" seo_keywords="Residential" seo_description="Residential" ParentName="Realestate"/>
<BlogCategory ID="24" ParentID="3" Name="Commercial" Active="1" seo_keywords="Commercial" seo_description="Commercial" ParentName="Realestate"/>
<BlogCategory ID="25" ParentID="3" Name="Advice" Active="1" seo_keywords="Advice" seo_description="Advice" ParentName="Realestate"/>
<BlogCategory ID="26" ParentID="3" Name="Loans" Active="1" seo_keywords="Loans" seo_description="Loans" ParentName="Realestate"/>
<BlogCategory ID="27" ParentID="4" Name="Internet" Active="1" seo_keywords="Internet" seo_description="Internet" ParentName="Technology"/>
<BlogCategory ID="28" ParentID="4" Name="Apps" Active="1" seo_keywords="Apps" seo_description="Apps" ParentName="Technology"/>
<BlogCategory ID="29" ParentID="4" Name="Softwares" Active="1" seo_keywords="Softwares" seo_description="Softwares" ParentName="Technology"/>
<BlogCategory ID="30" ParentID="4" Name="Robotics" Active="1" seo_keywords="Robotics" seo_description="Robotics" ParentName="Technology"/>
<BlogCategory ID="31" ParentID="5" Name="Movies" Active="1" seo_keywords="Movies" seo_description="Movies" ParentName="Entertainment "/>
<BlogCategory ID="32" ParentID="5" Name="Gaming" Active="1" seo_keywords="Gaming" seo_description="Gaming" ParentName="Entertainment "/>
<BlogCategory ID="33" ParentID="5" Name="Music" Active="1" seo_keywords="Music" seo_description="Music" ParentName="Entertainment "/>
<BlogCategory ID="34" ParentID="4" Name="TeleVision" Active="1" seo_keywords="TeleVision" seo_description="TeleVision" ParentName="Technology"/>
<BlogCategory ID="35" ParentID="5" Name="Celebrity " Active="1" seo_keywords="Celebrity " seo_description="Celebrity " ParentName="Entertainment "/>
<BlogCategory ID="36" ParentID="6" Name="Parenting" Active="1" seo_keywords="Parenting" seo_description="Parenting" ParentName="LifeStyle"/>
<BlogCategory ID="37" ParentID="6" Name="Kids" Active="1" seo_keywords="Kids" seo_description="Kids" ParentName="LifeStyle"/>
<BlogCategory ID="38" ParentID="6" Name="Fashion" Active="1" seo_keywords="Fashion" seo_description="Fashion" ParentName="LifeStyle"/>
<BlogCategory ID="39" ParentID="7" Name="Mobile" Active="1" seo_keywords="Mobile" seo_description="Mobile" ParentName="Electronics "/>
<BlogCategory ID="40" ParentID="7" Name="Tab" Active="1" seo_keywords="Tab" seo_description="Tab" ParentName="Electronics "/>
<BlogCategory ID="41" ParentID="7" Name="Computers" Active="1" seo_keywords="Computers" seo_description="Computers" ParentName="Electronics "/>
<BlogCategory ID="42" ParentID="7" Name="Laptops" Active="1" seo_keywords="Laptops" seo_description="Laptops" ParentName="Electronics "/>
<BlogCategory ID="43" ParentID="7" Name="Home Applicances" Active="1" seo_keywords="Home Applicances" seo_description="Home Applicances" ParentName="Electronics "/>
<BlogCategory ID="44" ParentID="8" Name="Courses" Active="1" seo_keywords="Courses" seo_description="Courses" ParentName="Education"/>
<BlogCategory ID="45" ParentID="8" Name="Exams" Active="1" seo_keywords="Exams" seo_description="Exams" ParentName="Education"/>
<BlogCategory ID="46" ParentID="8" Name="Training" Active="1" seo_keywords="Training" seo_description="Training" ParentName="Education"/>
<BlogCategory ID="47" ParentID="8" Name="Quiz" Active="1" seo_keywords="Quiz" seo_description="Quiz" ParentName="Education"/>
<BlogCategory ID="48" ParentID="8" Name="Book Reviews" Active="1" seo_keywords="Book Reviews" seo_description="Book Reviews" ParentName="Education"/>
<BlogCategory ID="49" ParentID="8" Name="Institutions" Active="1" seo_keywords="Institutions" seo_description="Institutions" ParentName="Education"/>
<BlogCategory ID="50" ParentID="8" Name="Universe" Active="1" seo_keywords="Universe" seo_description="Universe" ParentName="Education"/>
<BlogCategory ID="51" ParentID="9" Name="Startups" Active="1" seo_keywords="Startups" seo_description="Startups" ParentName="Business "/>
<BlogCategory ID="52" ParentID="9" Name="Small Scale" Active="1" seo_keywords="Small Scale" seo_description="Small Scale" ParentName="Business "/>
<BlogCategory ID="53" ParentID="9" Name="Market" Active="1" seo_keywords="Market" seo_description="Market" ParentName="Business "/>
<BlogCategory ID="54" ParentID="9" Name="Finance " Active="1" seo_keywords="Finance " seo_description="Finance " ParentName="Business "/>
<BlogCategory ID="55" ParentID="9" Name="Expert Tips" Active="1" seo_keywords="Expert Tips" seo_description="Expert Tips" ParentName="Business "/>
<BlogCategory ID="56" ParentID="9" Name="Online Business" Active="1" seo_keywords="Online Business" seo_description="Online Business" ParentName="Business "/>
<BlogCategory ID="57" ParentID="10" Name="Cricket" Active="1" seo_keywords="Cricket" seo_description="Cricket" ParentName="Sports"/>
<BlogCategory ID="58" ParentID="10" Name="Football" Active="1" seo_keywords="Football" seo_description="Football" ParentName="Sports"/>
<BlogCategory ID="59" ParentID="10" Name="Tennis" Active="1" seo_keywords="Tennis" seo_description="Tennis" ParentName="Sports"/>
<BlogCategory ID="60" ParentID="10" Name="Formula1" Active="1" seo_keywords="Formula1" seo_description="Formula1" ParentName="Sports"/>
<BlogCategory ID="61" ParentID="10" Name="Other Sports" Active="1" seo_keywords="Other Sports" seo_description="Other Sports" ParentName="Sports"/>
<BlogCategory ID="62" ParentID="11" Name="Car" Active="1" seo_keywords="Car" seo_description="Car" ParentName="Auto "/>
<BlogCategory ID="63" ParentID="11" Name="Bike" Active="1" seo_keywords="Bike" seo_description="Bike" ParentName="Auto "/>
<BlogCategory ID="64" ParentID="11" Name="MotorHomes" Active="1" seo_keywords="MotorHomes" seo_description="MotorHomes" ParentName="Auto "/>
<BlogCategory ID="65" ParentID="12" Name="Interviews" Active="1" seo_keywords="Interviews" seo_description="Interviews" ParentName="Jobs"/>
<BlogCategory ID="66" ParentID="12" Name="Career" Active="1" seo_keywords="Career" seo_description="Career" ParentName="Jobs"/>
<BlogCategory ID="67" ParentID="12" Name="Govt Jobs" Active="1" seo_keywords="Govt Jobs" seo_description="Govt Jobs" ParentName="Jobs"/>
<BlogCategory ID="68" ParentID="12" Name="PSU" Active="1" seo_keywords="PSU" seo_description="PSU" ParentName="Jobs"/>
<BlogCategory ID="69" ParentID="12" Name="Bank Jobs" Active="1" seo_keywords="Bank Jobs" seo_description="Bank Jobs" ParentName="Jobs"/>
<BlogCategory ID="70" ParentID="12" Name="Home Based" Active="1" seo_keywords="Home Based" seo_description="Home Based" ParentName="Jobs"/>
<BlogCategory ID="71" ParentID="0" Name="Videos" Active="1" seo_keywords="Movies Funny Videos, Prank Videos, Sexy Videos " seo_description="Movies Videos " ParentName=""/>
<BlogCategory ID="72" ParentID="71" Name="Movies Funny Videos" Active="1" seo_keywords="Movies Funny Videos, Bollywood Funny Videos, Hollywood Funny Videos" seo_description="Movies Funny Videos" ParentName="Videos"/>
<BlogCategory ID="73" ParentID="71" Name="Facebook Videos " Active="1" seo_keywords="Facebook Videos, Facebook Funny Videos, Facebook Prank Videos " seo_description="Facebook Videos, Facebook Funny Videos, Facebook Prank Videos " ParentName="Videos"/>
<BlogCategory ID="74" ParentID="71" Name="Prank Videos " Active="1" seo_keywords="Prank Videos " seo_description="Prank Videos " ParentName="Videos"/>
<BlogCategory ID="75" ParentID="71" Name="TV Show Video" Active="1" seo_keywords="Watch TV Show Video" seo_description="Watch TV Show Video" ParentName="Videos"/>
<BlogCategory ID="1075" ParentID="71" Name="Animal Viral Videos" Active="1" seo_keywords="Animal Viral Videos" seo_description="Animal Viral Videos" ParentName="Videos"/>
<BlogCategory ID="1076" ParentID="71" Name="News Video" Active="1" seo_keywords="Watch New Videos, Watch News Debates, Watch Daily News " seo_description="Watch New Videos, Watch News Debates, Watch Daily News " ParentName="Videos"/>
<BlogCategory ID="1077" ParentID="71" Name="Dance Video" Active="1" seo_keywords="Dance Video" seo_description="Dance Video" ParentName="Videos"/>
<BlogCategory ID="1078" ParentID="5" Name="TV Shows " Active="1" seo_keywords="TV Shows " seo_description="TV Shows " ParentName="Entertainment "/>
<BlogCategory ID="1079" ParentID="4" Name="Solar System " Active="1" seo_keywords="Solar System " seo_description="Solar System " ParentName="Technology"/>
<BlogCategory ID="1080" ParentID="9" Name="Services" Active="1" seo_keywords="Services " seo_description="Services" ParentName="Business "/>
<Parent Id="1" ParentName="Travel"/>
<Parent Id="2" ParentName="HealthCare"/>
<Parent Id="3" ParentName="Realestate"/>
<Parent Id="4" ParentName="Technology"/>
<Parent Id="5" ParentName="Entertainment "/>
<Parent Id="6" ParentName="LifeStyle"/>
<Parent Id="7" ParentName="Electronics "/>
<Parent Id="8" ParentName="Education"/>
<Parent Id="9" ParentName="Education"/>
<Parent Id="10" ParentName="Business "/>
<Parent Id="11" ParentName="Sports"/>
<Parent Id="12" ParentName="Auto"/>
<Parent Id="13" ParentName="Jobs"/>
</BlogCategories>
 
MY XSLT..
<?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"/>-->
<xsl:template match="/*">
<div class="drop-down grid-col-12 effect-fade">
<div class="grid-col-12" style="padding-bottom: 0px;">
<div class="grid-col-10">
<h3>By Blog Category</h3>
</div>
<div class="grid-col-2" style="float:right">
<a href="/User/Registration">Post your Blog</a>
</div>
</div>
<div class="grid-row">
<xsl:for-each select="Parent">
<div class="grid-row3">
<ul>
<a href="">
<xsl:value-of select="@ParentName"></xsl:value-of>
</a>
<xsl:for-each select="BlogCategory">
<xsl:if test="@ID=@ParentID">
<li>
<a href="">
<xsl:value-of select="@Name"></xsl:value-of>
</a>
</li>
</xsl:if>
</xsl:for-each>
</ul>
</div>
</xsl:for-each>
</div>
</div>
<!--<table>
<tr>
<th>ID</th>
<th>Name</th>
<th>ParentID</th>
<th>ParentName</th>
<th>Seo_Keywords</th>
<th>Seo_Discription</th>
</tr>-->
<!--</table>-->
</xsl:template>
</xsl:stylesheet>
 

Answers (2)