Copied to clipboard

Flag this post as spam?

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


  • Claushingebjerg 936 posts 2571 karma points
    Oct 26, 2012 @ 14:52
    Claushingebjerg
    0

    Sorting fields in xslt formatted email

    When i use contou to send email, it doesnt look very nice, sp i would like to use xslt formatted email.

    The thing is, when using xslt formatted email, the fileds come out in what seems to be absolutely random order?!? The random order makes the form unusable for the reciever!

    How do fix this? below is the same mail sent as unformatted and xslt formatted:

    Im using the following xslt for format the mail

    <xsl:template match="/">
    
    
    
              <table style="border-collapse:collapse;border:1px solid black;">
                      <xsl:for-each select="$records//fields/child::*">
                              <tr style="border:1px solid black;">
                                      <td valign="top" style="border:1px solid black;padding:5px;font-family:Verdana,Helvetica,Arial,sans-serif;font-size:11px;">
                                              <strong>
                                                    <xsl:value-of select="./caption"/>
                                              </strong>
                                      </td>
                                      <td valign="top" style="border:1px solid black;padding:5px;font-family:Verdana,Helvetica,Arial,sans-serif;font-size:11px;">
                                              <xsl:choose>
                                                      <xsl:when test="contains(.//value, '/umbraco/plugins/umbracoContour/files/')">
                                                              <a href="http://{umbraco.library:RequestServerVariables('SERVER_NAME')}{.//value}">
                                                                      <xsl:value-of select=".//value"/>
                                                              </a>
                                                      </xsl:when>
                                                      <xsl:otherwise>
                                                              <xsl:for-each select="./values/value">
                                                                      <xsl:if test="position() &gt; 1">
                                                                              <br />
                                                                      </xsl:if>
                                                                      <xsl:value-of select="umbraco.library:ReplaceLineBreaks(.)"/>
                                                              </xsl:for-each>
                                                      </xsl:otherwise>
                                              </xsl:choose>
                                            </td>
                              </tr>
                      </xsl:for-each>
              </table>
      </xsl:template>
  • Grant Thomas 291 posts 324 karma points
    Oct 26, 2012 @ 15:06
    Grant Thomas
    0

    In order to achieve this just lay out your data by referencing the fields explicitly instead of relying on the incoming order; so, instead of just getting the input and looping over it, specify each field like so (for example):

    <xsl:value-of select="$records//fields/firstnames//value"/>
  • Claushingebjerg 936 posts 2571 karma points
    Oct 26, 2012 @ 15:11
    Claushingebjerg
    0

    Is that really the only way? Thats gonna be a lot of work for something that ought to be automatic?!?

    Is there an easy way to see the xml structure of a form, so i dont have to guess the correct fild names?

     

  • Grant Thomas 291 posts 324 karma points
    Oct 26, 2012 @ 15:21
    Grant Thomas
    0

    Why ought it be automatic? This is a common misconception and trips people up when using collections in programming frameworks all the time - unless the collection of things is specfically marked as or dedicated to managed an ordered, sorted list, then it simply can't be (and shouldn't expect to be able to be) relied upon to give you results in the order you want. Mostly, unless the collection has an ordering requirement, collections are programmed for performance, not an individuals preference.

    What if the implementation of the collection changed in a future release, therefore, as a side-effect, breaking ALL of your prettified rendered representations?

    You could perhaps use some sorting methods of XSLT (<xsl:sort select=''>, for example), but to my knowledge all collection items would need to share a property to sort on.

  • Claushingebjerg 936 posts 2571 karma points
    Oct 26, 2012 @ 15:33
    Claushingebjerg
    0

    Im obviously no programmer - im a designer/frontend.

    From a user stand point i think its confusing that there are 2 radically different ways to send/recieve an email from contour.

    1. is unformatted and sorted the way the form is sorted in the UI. This makes sense

    2. is formatted and sorted by chaos... - This makes no sense. Who would want that? Formatted, YES - Chaos, NO!

    In my eyes both options should send data in the same order.

  • Claushingebjerg 936 posts 2571 karma points
    Oct 26, 2012 @ 15:55
    Claushingebjerg
    0

    Your solution works, thanks!

    But it kinda defeats the purpose of letting editors build their own forms.

     

Please Sign in or register to post replies

Write your reply to:

Draft