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 :-)
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"
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? :-)
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 ?
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
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 ?
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
I have created xslt ...this is that xslt ....
"Value was either too large or too small for an Int32. " error comes while saving xslt ....
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
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 "
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
is working on a reply...