Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
Hello Umbraco Community.
I'm currently banging my head against a wall. My problem is that i'm trying to change the value of a <xsl:variable name="news_background_color">green</xsl:variable> inside of my <xsl:for-each....
MY full XSLT code is right here:
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp " "> ]><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" exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets "><xsl:output method="xml" omit-xml-declaration="yes"/><xsl:param name="currentPage"/><xsl:variable name="news_background_color">green</xsl:variable> <---- WANT TO CHANGE THIS ONE<xsl:template match="/"><!-- The fun starts here --><xsl:for-each select="$currentPage/* [@isDoc and string(umbracoNaviHide) != '1']"> <xsl:sort select="@createDate" order="descending"/> <div id="news_list_{$news_background_color}"> <p class="news_date"><xsl:value-of select="umbraco.library:LongDate(@createDate)"/></p> <h2><xsl:value-of select="@nodeName"/></h2> <p class="news_teaser"> <xsl:value-of select="newsSummary"/> </p> <p class="read_more"><a class="read_more" href="{umbraco.library:NiceUrl(@id)}">Read more...</a></p> </div> <xsl:choose> <----from here---| <xsl:when test="$news_background_color='green'"> | <xsl:variable name="news_background_color">white</xsl:variable> | </xsl:when> | <xsl:otherwise> | <xsl:variable name="news_background_color">green</xsl:variable> | </xsl:otherwise> | </xsl:choose> <-----to here----|</xsl:for-each></xsl:template></xsl:stylesheet>
But i'm completely lost at the moment. So hoping that some of you guys can help me.
Regards,
Mark W. Nielsen.
I solved the problem after some searching for alternative (but easier) methods.
I changed the ideer about using a variable, and instead i choosed to use simple mats. You can see the new XSLT code right here:
<xsl:param name="currentPage"/><xsl:variable name="news_position" select="position()"/><xsl:template match="/"><!-- The fun starts here --><xsl:for-each select="$currentPage/* [@isDoc and string(umbracoNaviHide) != '1']"> <xsl:sort select="@createDate" order="descending"/> <xsl:choose> <xsl:when test="position() mod 2 = 1"> <div id="news_list_green"> <p class="news_date"><xsl:value-of select="umbraco.library:LongDate(@createDate)"/></p> <h2><xsl:value-of select="@nodeName"/></h2> <p class="news_teaser"> <xsl:value-of select="newsSummary"/> </p> <p class="read_more"><a class="read_more" href="{umbraco.library:NiceUrl(@id)}">Read more...</a></p> </div> </xsl:when> <xsl:otherwise> <div id="news_list_white"> <p class="news_date"><xsl:value-of select="umbraco.library:LongDate(@createDate)"/></p> <h2><xsl:value-of select="@nodeName"/></h2> <p class="news_teaser"> <xsl:value-of select="newsSummary"/> </p> <p class="read_more"><a class="read_more" href="{umbraco.library:NiceUrl(@id)}">Read more...</a></p> </div> </xsl:otherwise> </xsl:choose></xsl:for-each></xsl:template></xsl:stylesheet>
So what i did is to use the position instead, and that combined with some simple math make it all work like it should.
Mark W. Nielsen
Hi Mark,
Am nto sure waht you are trying to achive her. Do you want to alternate the background color of your DIV in the loop?
//fuji
That was excatly what i was trying to... :)
Great you got it working.:)
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
Change value of XSLT Variable inside a for-each
Hello Umbraco Community.
I'm currently banging my head against a wall. My problem is that i'm trying to change the value of a <xsl:variable name="news_background_color">green</xsl:variable> inside of my <xsl:for-each....
MY full XSLT code is right here:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp " "> ]>
<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"
exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets ">
<xsl:output method="xml" omit-xml-declaration="yes"/>
<xsl:param name="currentPage"/>
<xsl:variable name="news_background_color">green</xsl:variable> <---- WANT TO CHANGE THIS ONE
<xsl:template match="/">
<!-- The fun starts here -->
<xsl:for-each select="$currentPage/* [@isDoc and string(umbracoNaviHide) != '1']">
<xsl:sort select="@createDate" order="descending"/>
<div id="news_list_{$news_background_color}">
<p class="news_date"><xsl:value-of select="umbraco.library:LongDate(@createDate)"/></p>
<h2><xsl:value-of select="@nodeName"/></h2>
<p class="news_teaser">
<xsl:value-of select="newsSummary"/>
</p>
<p class="read_more"><a class="read_more" href="{umbraco.library:NiceUrl(@id)}">Read more...</a></p>
</div>
<xsl:choose> <----from here---|
<xsl:when test="$news_background_color='green'"> |
<xsl:variable name="news_background_color">white</xsl:variable> |
</xsl:when> |
<xsl:otherwise> |
<xsl:variable name="news_background_color">green</xsl:variable> |
</xsl:otherwise> |
</xsl:choose> <-----to here----|
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
But i'm completely lost at the moment. So hoping that some of you guys can help me.
Regards,
Mark W. Nielsen.
I solved the problem after some searching for alternative (but easier) methods.
I changed the ideer about using a variable, and instead i choosed to use simple mats. You can see the new XSLT code right here:
<xsl:param name="currentPage"/>
<xsl:variable name="news_position" select="position()"/>
<xsl:template match="/">
<!-- The fun starts here -->
<xsl:for-each select="$currentPage/* [@isDoc and string(umbracoNaviHide) != '1']">
<xsl:sort select="@createDate" order="descending"/>
<xsl:choose>
<xsl:when test="position() mod 2 = 1">
<div id="news_list_green">
<p class="news_date"><xsl:value-of select="umbraco.library:LongDate(@createDate)"/></p>
<h2><xsl:value-of select="@nodeName"/></h2>
<p class="news_teaser">
<xsl:value-of select="newsSummary"/>
</p>
<p class="read_more"><a class="read_more" href="{umbraco.library:NiceUrl(@id)}">Read more...</a></p>
</div>
</xsl:when>
<xsl:otherwise>
<div id="news_list_white">
<p class="news_date"><xsl:value-of select="umbraco.library:LongDate(@createDate)"/></p>
<h2><xsl:value-of select="@nodeName"/></h2>
<p class="news_teaser">
<xsl:value-of select="newsSummary"/>
</p>
<p class="read_more"><a class="read_more" href="{umbraco.library:NiceUrl(@id)}">Read more...</a></p>
</div>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
So what i did is to use the position instead, and that combined with some simple math make it all work like it should.
Regards,
Mark W. Nielsen
Hi Mark,
Am nto sure waht you are trying to achive her. Do you want to alternate the background color of your DIV in the loop?
//fuji
That was excatly what i was trying to... :)
Great you got it working.:)
//fuji
is working on a reply...