Answered XSLT

  • Wednesday, December 05, 2012 10:44 PM
     
     
    Hi,

    I have a scenario like.... If the image is present  then display the image and fallowed by text like below:

    <div class1>
       <div class2>

             Image
        </div>

    (some text)

    </div>..................Main div  close


    If image is not there display only text.

    <div class1>

    (some text)

    </div>

    below is the xml:


    <root>

    <child1>

    <body>
    <text>
    sometext
    </text>
    <image>
    img
    </image>
    </child1>
    <child2>
    ...
    <child2>

    can we achieve this with XSLT?

All Replies

  • Thursday, December 06, 2012 11:40 AM
     
     Answered

    <div class="class1">
          <xsl:if test="string-length(//image) &gt; 0">
            <div class="class2">
              <xsl:value-of select="//image" />
            </div>
          </xsl:if>
          <xsl:value-of select="//text" />
    </div>

    Morten la Cour

    • Marked As Answer by Dudy_22 Thursday, December 06, 2012 6:28 PM
    •  
  • Friday, December 07, 2012 2:56 PM
     
     

    Thanks for your reply..I am very new to xslt..

    Is there any good tutorial to learn XSLT?

  • Friday, December 07, 2012 4:47 PM
     
     

    I think w3schools is a great place to start:

    http://www.w3schools.com/xsl/xsl_transformation.asp

    Morten la Cour