Copied to clipboard

Flag this post as spam?

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


  • Jo Ward 5 posts 25 karma points
    Apr 26, 2013 @ 08:06
    Jo Ward
    0

    Sending an xslt transformed email from Contour - looping on fieldset

    Hi guys,

    I'm new to xslt but have managed to tweak the sample xslt file to layout an email in a format more to my liking, however I've hit a bit of wall when working out how to reference a set of repeated fields. 

    Our form asks for basic contact details, followed by a number of repeating fields ie.

    NAME:
    ADDRESS::

    TITLE:
    AUTHOR:
    JOURNAL:
    YEAR, VOL & ISS, PAGES:

    TITLE:
    AUTHOR:
    JOURNAL:
    YEAR, VOL & ISS, PAGES:

    TITLE:
    AUTHOR:
    JOURNAL:
    YEAR, VOL & ISS, PAGES:

    I can pull the first instance of Title like so :

    <xsl:value-of select="$records//fields/child::* [caption[1] = 'Title']//value"/>
    <xsl:value-of select="$records//fields/child::* [caption[1] = 'Author']//value"/>

    etc..

    but i'm having difficulty getting the 2nd and 3rd sets. I would have thought 

    <xsl:value-of select="$records//fields/child::* [caption[2] = 'Title']//value"/>
    <xsl:value-of select="$records//fields/child::* [caption[2] = 'Author']//value"/>
    etc.

    would work, but I get nothing. Any pointers?

    Additionally, the repeated fields are contained within a fieldset, so each instance of a field has a fieldsetindex attribute. Is it at all possible to use fieldsetindex to loop through each fieldset in turn and output the value of each of these fields?

    Ultimately, I'd like to update the form to allow the user to add as many of these repeated fields as they need, so pulling the data via a loop is by the preferred option...

    All help very much appreciated!

  • Comment author was deleted

    Apr 26, 2013 @ 10:02

    Hmmm could you try <xsl:value-of select="$records//fields/child::* [caption = 'Title'][2]//value"/>

  • Jo Ward 5 posts 25 karma points
    Apr 29, 2013 @ 06:05
    Jo Ward
    0

    Hi Tim,

    Thanks for that - it works! Much appreciated.

    Now, if anyone has any ideas how I can loop!??!?!

  • Jo Ward 5 posts 25 karma points
    Apr 30, 2013 @ 08:28
    Jo Ward
    0

    If anyone is interested, I managed to solve this by repeating on one of the repeating fields, and using 'following-sibling' to get the values of the others ie:

         <xsl:for-each select="$records//fields/child::* [caption = 'Title']">
            <xsl:choose>
              <xsl:when test=".//value != ''">
                <tr>
                  <td><strong>TITLE:</strong></td>
                  <td><xsl:value-of select=".//value"/></td>
                </tr>
              </xsl:when>
            </xsl:choose>
            <xsl:choose>
              <xsl:when test="following-sibling::*[1]//value != ''">
                <tr>
                  <td><strong>AUTHOR:</strong></td>
                  <td><xsl:value-of select="following-sibling::*[1]//value"/></td>
                </tr>
              </xsl:when>
            </xsl:choose>
            <xsl:choose>
              <xsl:when test="following-sibling::*[2]//value != ''">
                <tr>
                  <td><strong>JOURNAL:</strong></td>
                  <td><xsl:value-of select="following-sibling::*[2]//value"/></td>
                </tr>
              </xsl:when>
            </xsl:choose>
            <xsl:choose>
              <xsl:when test="following-sibling::*[3]//value != ''">
                <tr>
                  <td><strong>YEAR, VOL &amp; ISS, PAGES:</strong></td>
                  <td><xsl:value-of select="following-sibling::*[3]//value"/></td>
                </tr>
              </xsl:when>
            </xsl:choose>
          </xsl:for-each>

     

Please Sign in or register to post replies

Write your reply to:

Draft