Copied to clipboard

Flag this post as spam?

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


  • Delete me 45 posts 66 karma points
    Sep 29, 2009 @ 10:42
    Delete me
    0

    Choose and For-each

    A stupid question I am sure, but here is what I am trying to do:

    <xsl:choose>
    <xsl:when test="$prev_dates=1">
    <xsl:for-each select="$currentPage/node [string(data [@alias='umbracoNaviHide']) != '1' and(umbraco.library:FormatDateTime(data[@alias='dato'],'yyyyMMdd') &gt;= umbraco.library:FormatDateTime(umbraco.library:CurrentDate(),'yyyyMMdd'))]">
    </xsl:when>
    <xsl:otherwise>
    <xsl:for-each select="$currentPage/node [string(data [@alias='umbracoNaviHide']) != '1' and(umbraco.library:FormatDateTime(data[@alias='dato'],'yyyyMMdd') &lt; umbraco.library:FormatDateTime(umbraco.library:CurrentDate(),'yyyyMMdd'))]">
    </xsl:otherwise>
    </xsl:choose>

    .. I know this doesnt work, but what are the proper method to do this in XSLT?

    Thanks in advance!

  • Josh Townson 67 posts 162 karma points
    Sep 29, 2009 @ 11:20
    Josh Townson
    0

    That seems perfectly reasonalbe to me, you just need to put some logic in the <xsl:for-each> blocks (and then close them). I would recommend using an <xsl:template> to combine the code so you only have to write it once...

    <?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"
    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:template match="/">
    <!-- ... -->
    <xsl:choose>

    <xsl:when test="$prev_dates=1">
    <xsl:for-each select="$currentPage/node [string(data [@alias='umbracoNaviHide']) != '1' and(umbraco.library:FormatDateTime(data[@alias='dato'],'yyyyMMdd') &gt;= umbraco.library:FormatDateTime(umbraco.library:CurrentDate(),'yyyyMMdd'))]">
    <xsl:call-template name="doSomething">
    <xsl:with-param name="item" select="."/>
    </xsl:call-template>
    </xsl:for-each>
    </xsl:when>
    <xsl:otherwise>
    <xsl:for-each select="$currentPage/node [string(data [@alias='umbracoNaviHide']) != '1' and(umbraco.library:FormatDateTime(data[@alias='dato'],'yyyyMMdd') &lt; umbraco.library:FormatDateTime(umbraco.library:CurrentDate(),'yyyyMMdd'))]">
    <xsl:call-template name="doSomething">
    <xsl:with-param name="item" select="."/>
    </xsl:call-template>
    </xsl:for-each>
    </xsl:otherwise>
    </xsl:choose>
    </xsl:template>

    <xsl:template name="doSomething"><!-- This just prints the nodeName of item -->
    <xsl:param name="item"/>
    <p><xsl:value-of select="$item/@nodeName"/></p>
    </xsl:template>
    </xsl:stylesheet>
  • Delete me 45 posts 66 karma points
    Sep 29, 2009 @ 11:57
    Delete me
    0

    Great, thanks!!

  • 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.

Please Sign in or register to post replies