Prasun Kanakam

Prasun Kanakam

  • NA
  • 6
  • 604

Transformation of XML to HTML using XSLt

May 17 2019 10:19 AM
I have an XML as:
  1.  <a>  
  2.    <b>  
  3.       <c>  
  4.             <source>   
  5.                   <title value ="Apple"/>   
  6.                      some more tags  
  7.                      .  
  8.                      .  
  9.                      .   
  10.             </source>  
  11.                     
  12.                   <source>  
  13.                         <title value ="Mango"/>  
  14.                            some more tags  
  15.                               .  
  16.                               .  
  17.                               .  
  18.                    </source>  
  19.    
  20.                   <source>  
  21.                         <title value ="Banana"/>  
  22.                               some more tags  
  23.                               .  
  24.                               .  
  25.                               .  
  26.                   </source>  
  27.                     
  28.                <source>  
  29.                   <title value =" Grapes"/>  
  30.                      <some more tags>  
  31.                         .  
  32.                         .  
  33.                         .  
  34.                </source>  
  35. </c>  
  36. </b>  
  37. </a>   
Based on my input(supose if my input is "title = Banana" I want to display all info related that tag.
 
I want to display the selected <title> and related <tags> values under that.
 
eg: Mango, Banana
 
XSLT :
  1. <xsl:template match="/">  
  2. <html>  
  3. <body>  
  4. <xsl:apply-templates select="source"/>  
  5. </body>  
  6. </html>  
  7. </xsl:template>  
  8. <xsl:template match="source">  
  9. <xsl:choose>  
  10. <xsl:when test="source[@value='Banana']">  
  11. <xsl:value-of select="source[@value='Banana']"/>  
  12. </xsl:when>  
  13. <xsl:otherwise>  
  14. <xsl:value-of select="$untitled_section"/>  
  15. </xsl:otherwise>  
  16. </xsl:choose>  
  17. </xsl:template>  
Desire HTML output:
 
Banana
(some more tags deatils)......
(some more tags deatils)......
(some more tags deatils)......
(some more tags deatils)......
(some more tags deatils)......

Answers (2)