locked
DataFormWebPart and Lookup column with multiple values RRS feed

  • Question

  • I have a DataFormWebPart connected to a custom list datasource. The custom list has a Lookup column that allows multiple values.

     

    I would like to display the lookup values as a link directly to the correct lookup list item.

     

    How could I best do this?

    Wednesday, June 11, 2008 6:40 PM

Answers

  • One way that it *can* be accomplished is by splitting the multivalue string and creating the links manually:

     

    <xsl:variable name="norm_resp" select="concat(@MultiValueLookupString,';')"/>
     <xsl:call-template name="split">
     <xsl:with-param name="input" select="$norm_resp"/>
    </xsl:call-template>


    <xsl:template name="split">
     <xslStick out tonguearam name="input"/>
     <xsl:if test="$input">
      <xsl:variable name="title" select="substring-before($input,';')"/>
      <xsl:variable name="titleurl" select="concat('CustomUrl.aspx?title=',$title)"/>
      <a>
       <xsl:attribute name="href"><xsl:value-of select="$titleurl"/></xsl:attribute>
       <xsl:value-of select="$title"/><br/>
      </a>
      <xsl:call-template name="split">
       <xsl:with-param name="input" select="substring-after($input,';')"/>
      </xsl:call-template>
     </xsl:if>     
    </xsl:template>


    Seems a shame to have to use this as Sharepoint can generate the links out of the box for non custom ListForms.

     

    If anybody knows a better solution, then would love to hear it.

    Monday, June 23, 2008 7:37 AM

All replies

  • Have discovered how to automatically create a link from a lookup column, BUT only in the case of one value it seems (so not multiple which is what I need).

     

    For one lookup value the following seems to work:

     

    <a href="{ddwrt:URLLookup('{GUID of list containing lookup item}', 'name of lookup column in this list', string(@ID))}">....</a>

     

    Anybody any clue how to handle multiple lookup values?

     

    Wednesday, June 18, 2008 1:37 PM
  • One way that it *can* be accomplished is by splitting the multivalue string and creating the links manually:

     

    <xsl:variable name="norm_resp" select="concat(@MultiValueLookupString,';')"/>
     <xsl:call-template name="split">
     <xsl:with-param name="input" select="$norm_resp"/>
    </xsl:call-template>


    <xsl:template name="split">
     <xslStick out tonguearam name="input"/>
     <xsl:if test="$input">
      <xsl:variable name="title" select="substring-before($input,';')"/>
      <xsl:variable name="titleurl" select="concat('CustomUrl.aspx?title=',$title)"/>
      <a>
       <xsl:attribute name="href"><xsl:value-of select="$titleurl"/></xsl:attribute>
       <xsl:value-of select="$title"/><br/>
      </a>
      <xsl:call-template name="split">
       <xsl:with-param name="input" select="substring-after($input,';')"/>
      </xsl:call-template>
     </xsl:if>     
    </xsl:template>


    Seems a shame to have to use this as Sharepoint can generate the links out of the box for non custom ListForms.

     

    If anybody knows a better solution, then would love to hear it.

    Monday, June 23, 2008 7:37 AM
  • Thanks VERY MUCH Jan - this was a lifesaver.

    At first, I was tempted to keep looking, because I'm not comfortable w/XSL yet, so I was thinking about a Javascript function.  But then, I figured I need to learn XSL sooner or later, so I gave it a shot, and, once I moved the split template out of another template, it worked like a charm.

    Again - thanks for saving me a lot of time and energy, and teaching me XSL some :-)

    John
    Wednesday, March 25, 2009 10:16 PM