Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • vaibhav 119 posts 139 karma points
    Mar 26, 2011 @ 09:20
    vaibhav
    0

    image if uploaded then show

    Hello,

    If user uploads the image then some other div should be applied & if user does not upload image then some other div should be applied ....

    How to do this ?

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Mar 26, 2011 @ 09:39
    Jan Skovgaard
    0

    Hi Vaibhav

    Do you have made som code for this?

    And essentially you will ned the div anyway it seems. But perhaps youre thinking about a div with a different class or id attached?

    This is done by setting the <xsl:attribute /> element.

    For instance like this

    <div>
    <xsl:attribute name="class">
    <xsl:choose>
       <xsl:when test="$image">imageclass</xsl:when>
       <xsl:otherwise>noimageclass</xsl:otherwise>
    </xsl:choose>
    </xsl:attribute>

    <!-- The rest of your code goes here -->

    </div>

    In the above I asume you have already fetched the image in a media variable defined earlier in the code.

    In the first line you test to see if the variable contains anything. If it does the "imageclass" i set on the div. Otherwise the "noimageclass" is being set.

    Please be aware that when using the <xsl:attribue /> element it MUST be placed directly beneath the opening div tag. It must be the first piece of XSLT code as well.

    Bonusinfo: If you some day need to use this on an <input> elemnt the you can't use a self-closing input element but will need to use <input><xsl:attribute /> element here</input>. When rendered it's rendering perfectly valid as <input /> in the HTML source.

    I hope this answers your question. Otherwise please don't hesitate to ask again :-)

    /Jan

  • vaibhav 119 posts 139 karma points
    Mar 26, 2011 @ 10:08
    vaibhav
    0

    I have a small template in side both div

    If user uploads an image then one div will be applied & if not then other div will be applied.

    I just have that templates .

    In the above I asume you have already fetched the image in a media variable defined earlier in the code. ?    I just have one upload control from where user will select image.   & that propertoes name is "bdimage"

    I dident understood ur code.

    Can u explain it agian ?

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Mar 26, 2011 @ 11:37
    Jan Skovgaard
    0

    Hi Vaibhav

    Ok...but then it's really a matter of when/otherwise.

    <xsl:choose>
    <xsl:when test="$currentPage/bdimage">
    <div><!-- code goes here --></div>
    </xsl:when test>
    <xsl:otherwise>
    <div><!--code goes here --></div>
    </xsl:otherwise>
    </xsl:choose>

    I'm asuming you upload the image directly to a node using the upload datatype, right? :-)

    Hope the above makes sense.

    /Jan

  • vaibhav 119 posts 139 karma points
    Mar 26, 2011 @ 12:04
    vaibhav
    0

    I have created xslt ...this is that xslt ....

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp "&#x00A0;"> ]>
    <xsl:stylesheet
      version="1.0"
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      xmlns:msxml="urn:schemas-microsoft-com:xslt"
      xmlns:umbraco.library="urn:umbraco.library" xmlns:Exslt.ExsltCommon="urn:Exslt.ExsltCommon" xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes" xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath" xmlns:Exslt.ExsltRegularExpressions="urn:Exslt.ExsltRegularExpressions" xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings" xmlns:Exslt.ExsltSets="urn:Exslt.ExsltSets" xmlns:tagsLib="urn:tagsLib" xmlns:BlogLibrary="urn:BlogLibrary"
      exclude-result-prefixes="msxml
    umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes
    Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings
    Exslt.ExsltSets tagsLib BlogLibrary "
    >


    <xsl:output method="xml" omit-xml-declaration="yes"/>

    <xsl:param name="currentPage"/>

    <xsl:template match="/">

    <!-- start writing XSLT -->
    <xsl:choose>
    <xsl:when test="$currentPage/bdimage != ''">
    <div id="solutionsBlock3">
              <div id="newsiamge"><img src="{$currentPage/bdimage}" width="115px" height="90px"/></div>
              <div id="solcontent">
                  <div id="bold"><xsl:value-of select="umbraco.library:ReplaceLineBreaks(bg_Header)" disable-output-escaping="yes"/></div>
                  <div id="normal"><xsl:value-of select="umbraco.library:TruncateString(umbraco.library:ReplaceLineBreaks(solutionBlock3_content), 70,'')" disable-output-escaping="yes"/>
                      <xsl:if test="string-length(umbraco.library:ReplaceLineBreaks(bg_content) &gt; 70)">
                        <a href="{umbraco.library:NiceUrl(@id)}">  >> </a>  
                      </xsl:if>
                  </div>
              </div>
       </div>
    </xsl:when>
    <xsl:otherwise>
      <div id="solutionsBlock3">
              <div id="newsiamge"><img src="{$currentPage/bdimage}" width="115px" height="90px"/></div>
              <div id="solcontent">
                  <div id="bold"><xsl:value-of select="umbraco.library:ReplaceLineBreaks(bg_Header)" disable-output-escaping="yes"/></div>
                  <div id="normal"><xsl:value-of select="umbraco.library:TruncateString(umbraco.library:ReplaceLineBreaks(solutionBlock3_content), 70,'')" disable-output-escaping="yes"/>
                      <xsl:if test="string-length(umbraco.library:ReplaceLineBreaks(bg_content) &gt; 70)">
                        <a href="{umbraco.library:NiceUrl(@id)}">  >> </a>  
                      </xsl:if>
                  </div>
              </div>
       </div>
    </xsl:otherwise>
    </xsl:choose>

    </xsl:template>

    </xsl:stylesheet>

     

     

    "Value was either too large or too small for an Int32. "   error comes while saving xslt ....

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Mar 26, 2011 @ 12:12
    Jan Skovgaard
    0

    Hi Vaibhav

    Try checking the "Skip error" checkbox. Then the error should not occur. It's because the value of the image id is not known untill runtime. You can also avoid it by making an "if test" to see if the image has a value. Then this error should not occur.

    But I'm not sure I understand what it is you're trying to do with this? The code in the otherwise block looks completely identical to the code in the when block? Am I missing something? :-)

    /Jan

  • vaibhav 119 posts 139 karma points
    Mar 26, 2011 @ 12:46
    vaibhav
    0

    It is same right now .....i will change it afterwords to content without image.....

    when i skiped error ....then at run time error comes as "Error parsing XSLT file: \xslt\123.xslt "

     

  • Pasang Tamang 258 posts 458 karma points
    Mar 26, 2011 @ 16:18
    Pasang Tamang
    1

    Hi vaibhav

    You forgot to check either $currentPage/bgimage contains value or not. This may help you http://our.umbraco.org/forum/developers/xslt/18816-Get-media-problem

    Pnima

     

Please Sign in or register to post replies

Write your reply to:

Draft