Hi All, I would very much appreciate dsome help. I'm new to Umbraco, xslt and all things .net and I have hit a stumbling block. I have a for-each loop and I nned to add an asterisk to a variable during each loop. I have the following but the variable "bullet" never changes, it is always a single asterisk. What am I doing wrong?
As you will probably soon learn, XSLT demands a totally different approach than your average "normal" programming language (it's actually a lot more like CSS).
I'm just going to post a "solution" to what you're trying to do, and then you can ask anything you want about how it works, but try to wrap your head around as much as you can first, before shooting, OK?
<xsl:param name="currentPage" />
<!-- This can be optimized depending on Content structure -->
<xsl:variable name="bannerRoot" select="$currentPage/ancestor-or-self::root//umbHomepage[@nodeName = 'Homepage Banners']" />
<xsl:variable name="bullets" select="'**************************************************'" />
<xsl:template match="/">
<xsl:apply-templates select="$bannerRoot" />
</xsl:template>
<xsl:template match="HomepageBanner">
<a href="#">
<xsl:value-of select="substring($bullets, 1, position())" />
<xsl:value-of select="concat('Click here to expand and view full terms and conditions for the ', description)" />
</a>
</xsl:template>
Ah, thanks Chriztian. Makes perfect sense. The only question I have is; is ther no way to dynamically assign the number of asterisks in the bullets variable based on the number of Homepage Banner nodes? It is not likely to happen but if there were more banners than asterisks, the script would not function as it should.
For-each and string concatenating
Hi All,
I would very much appreciate dsome help. I'm new to Umbraco, xslt and all things .net and I have hit a stumbling block. I have a for-each loop and I nned to add an asterisk to a variable during each loop. I have the following but the variable "bullet" never changes, it is always a single asterisk. What am I doing wrong?
<?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="bullet" select="'*'" />
<xsl:template match="/">
<xsl:for-each select="umbraco.library:GetXmlNodeByXPath('.')/descendant-or-self::umbHomepage[@nodeName='Homepage Banners']/HomepageBanner">
<a href="#"><xsl:value-of select='$bullet' />Click here to expand and view full terms and conditions for the <xsl:value-of select='description' /></a><br/>');
<xsl:variable name="bullet" select="concat($bullet,'*')" />
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
Any help would be greatly appreciated
Thanks
Paul
Hi Paul,
Welcome to the forums!
As you will probably soon learn, XSLT demands a totally different approach than your average "normal" programming language (it's actually a lot more like CSS).
I'm just going to post a "solution" to what you're trying to do, and then you can ask anything you want about how it works, but try to wrap your head around as much as you can first, before shooting, OK?
/Chriztian
Ah, thanks Chriztian. Makes perfect sense. The only question I have is; is ther no way to dynamically assign the number of asterisks in the bullets variable based on the number of Homepage Banner nodes? It is not likely to happen but if there were more banners than asterisks, the script would not function as it should.
Thanks again for your speedy reply.
Hi Paul,
I thought that would come up :-)
Here's how you can do that:
/Chriztian
Perfect. I'm used to php so this is a completely new way of thinking! Thanks so much for your help!
Paul, you can always use "Razor" macros rather than XSLT, which will be a bit more familiar to you if you are a PHP developer. See http://our.umbraco.org/documentation/v480/Reference/Querying/DynamicNode/
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.