Anyway, its evolved since then at works as intened, albeit with even uglier code.
The heading for an article is in a box in the slider, and if the heading is too big it cant fit, therefor i have a test for string length to adjust the box size to accomodate the heading size.
<xsl:choose> <xsl:when test="$currentPage/@level = 1"> <div class="thumbnails"> <ul> <!--
"articleFontpageLink" is a document template boolean property, checks
if its true. Decides wether it should be listed or not--> <xsl:for-each select="$currentPage/descendant::*[@isDoc][not(umbracoNaviHide = 1)][string(articleFrontpageLink) = '1']">
<li> <div class="thumb"> <!-- Thumbnail for listed item --> <xsl:if test="count(current()/outputPictures) > 0"> <img src="/ImageGen.ashx?image={current()/outputPictures[position()=1]/DAMP[@fullMedia]/mediaItem/Image/umbracoFile}&width=70&height=64"/> </xsl:if> <p> <span class="title"> <xsl:value-of select="string(articleHeading)"/> </span> <br/> <!-- Text from listed item, to appear in the list itself --> <!-- <xsl:value-of select="umbraco.library:TruncateString(artikel-Teasertekst,70,'...')"/> --> </p> </div> <!-- Background image for highlighted item--> <a href="/ImageGen.ashx?image={current()/outputPictures[position()=1]/DAMP[@fullMedia]/mediaItem/Image/umbracoFile}&width=581&constrain=true"><xsl:value-of select="normalize-space('')"/></a> <a href="{umbraco.library:NiceUrl(@id)}"><xsl:value-of select="normalize-space('')"/></a> <xsl:choose> <xsl:when test="string-length('articleHeading') >= 15"> <div style="top:225px; left:0px; width:600px;"> <!-- Article header --> <h1><a href="{umbraco.library:NiceUrl(@id)}"> Større <xsl:attribute name="class"> <xsl:value-of select="article-color"/> </xsl:attribute> <xsl:value-of select="articleHeading"/> </a> </h1> <!-- Text excerpt from article--> <p><a href="{umbraco.library:NiceUrl(@id)}"> <xsl:value-of select="artikel-Teasertekst"/></a></p> </div> </xsl:when> <xsl:otherwise> <div style="top:200px; left:0px; width:600px;"> <!-- Article header --> <h1><a href="{umbraco.library:NiceUrl(@id)}"> <xsl:attribute name="class"> <xsl:value-of select="article-color"/> </xsl:attribute> <xsl:value-of select="articleHeading"/> </a> </h1> <!-- Text excerpt from article--> <p><a href="{umbraco.library:NiceUrl(@id)}"> <xsl:value-of select="artikel-Teasertekst"/></a></p> </div> </xsl:otherwise> </xsl:choose> </li> </xsl:for-each> </ul> </div> </xsl:when>
It was obvious that something was wrong with the test, but if i do anything else inside the "string-length" brackets, it gives an exception:
"ystem.Xml.Xsl.XslTransformException: Attribute and namespace nodes
cannot be added to the parent element after a text, comment, pi, or
sub-element node has already been added."
If i write string-length(articleHeading) (without the ' ' ) it gives that error, heck, it does so regardless of what i try. I must have missed something, or its just the code in general thats the problem.honestly the code above isnt all of it, i can post it if its relevant.
Sorry for the confusion. The issue is that your <xsl:attribute> tag needs to be DIRECTLY after the <a> tag (or whichever tag it should apply to). You cannot have any logic, text output, etc between the tag and the <xsl:attribute> tag.
In your original code you have the word "Større" in between the <a> and <xsl:attribute> tag. In the fixed code I pasted, the Større text is moved after the <xsl:attribute> tag
Ok thank you, i think ive gotten a step closer but not really there. Ive removed the ' ' form the string length, it accepted that now so thats a start, but from what i can see it doesnt jump down to the otherwise now.
That looks fine to me. Obviously it will only run the code in the <xsl:otherwise> if the articleHeading is < 20 characters. Are you saying that's not happening in that case? You could try outputting the length to debug, ie <xsl:value-of select="string-length(articleHeading)" />
Also, are both sets of code the same except for the <div> style? If so there are a couple ways you could simplify it, here's a quick example:
<div> <xsl:attribute name="style"> <xsl:choose> <xsl:when test="string-length(articleHeading) > 20">top:225px;</xsl:when> <xsl:otherwise>top:200px;</xsl:otherwise> </xsl:choose>left:0px;width:600px; </xsl:attribute> .. the rest of your code inside the div .. </div>
is what defines how big the box will be, and i think it somehow switched them around, dont ask me why or how, but after fiddling with the numbers, it seems that it DOES work after your suggestions, thank you!
Now the next step is optimizing the code, actually, the code ive written above is doubled in one big choose that determines if current page is on level 1 or 2. Ive been trying to cut the choose out entirely, but defining where currentpage is doesnt work. Oh well, thats for another day, a deadline is coming up and i dont have much time left to fiddle with stuff that "works". Again thank you for your time.
Choose test skips directly to Otherwise
Ok, this problem might be bigger but here goes:
Ive described what this is about in greater detail here:
http://our.umbraco.org/forum/developers/xslt/23187-Help-tidying-up-and-fixing-errors-with-a-List-Rotator
Anyway, its evolved since then at works as intened, albeit with even uglier code.
The heading for an article is in a box in the slider, and if the heading is too big it cant fit, therefor i have a test for string length to adjust the box size to accomodate the heading size.
It was obvious that something was wrong with the test, but if i do anything else inside the "string-length" brackets, it gives an exception:
"ystem.Xml.Xsl.XslTransformException: Attribute and namespace nodes cannot be added to the parent element after a text, comment, pi, or sub-element node has already been added."
If i write string-length(articleHeading) (without the ' ' ) it gives that error, heck, it does so regardless of what i try. I must have missed something, or its just the code in general thats the problem.honestly the code above isnt all of it, i can post it if its relevant.
Hi Frederik,
The problem is that your <xsl:attribute> tag needs to be directly after the tag you wish to use it on. So you should change this:
to this:
Or, if you've already done the article-color logic you can use this for shorthand:
Hope this helps,
Tom
Thank you for helping me, but i dont really understand your solution?
(btw, the "Større" is just there so i can see of it hits the "when" condition, its not supposed to be there for other than testing)
Sorry for the confusion. The issue is that your <xsl:attribute> tag needs to be DIRECTLY after the <a> tag (or whichever tag it should apply to). You cannot have any logic, text output, etc between the tag and the <xsl:attribute> tag.
In your original code you have the word "Større" in between the <a> and <xsl:attribute> tag. In the fixed code I pasted, the Større text is moved after the <xsl:attribute> tag
Does that make sense?
-Tom
Are you still getting errors if you remove the Store text? Or is your condition just not getting hit?
Also as you mentioned you should change string-length('articleHeading') to remove the quotes, ie string-length(articleHeading)
-Tom
Ok thank you, i think ive gotten a step closer but not really there. Ive removed the ' ' form the string length, it accepted that now so thats a start, but from what i can see it doesnt jump down to the otherwise now.
That looks fine to me. Obviously it will only run the code in the <xsl:otherwise> if the articleHeading is < 20 characters. Are you saying that's not happening in that case? You could try outputting the length to debug, ie <xsl:value-of select="string-length(articleHeading)" />
Also, are both sets of code the same except for the <div> style? If so there are a couple ways you could simplify it, here's a quick example:
-Tom
Ok, i think i got it now, the
<divstyle="top:225px; left:0px; width:600px;">
is what defines how big the box will be, and i think it somehow switched them around, dont ask me why or how, but after fiddling with the numbers, it seems that it DOES work after your suggestions, thank you!
Now the next step is optimizing the code, actually, the code ive written above is doubled in one big choose that determines if current page is on level 1 or 2. Ive been trying to cut the choose out entirely, but defining where currentpage is doesnt work. Oh well, thats for another day, a deadline is coming up and i dont have much time left to fiddle with stuff that "works". Again thank you for your time.
is working on a reply...