I have a Data View Part pulling from a list that has a lookup column to another list (title linked by ID)

And somewhere in the XSLT, it reads

<xsl:value-of select="@ColumnX"/>

Now since ColumnX is a reference to another list, how do I go about obtaining the ID rather than the text? Is there a ddwrt trick out there?

Note If you were to run the same CAML used by the Data View Web Part, you will notice that the ID of the referenced column is part of the result. E.g.

12;#Bill Peet

ps: It seems and I could be wrong that the DVWP removes the IDs so things like substring-before(string, string) won't work.

  • Have you checked to ensure that the value of @ColumnX includes the ID if you just output the variable raw. Obviously your not going to be able to peform substring operations is the original string doesn't have the ID. Im not talking about executing the same CAML query externally as you did, I mean output the value of @ColumnX and see what is contained within. Mar 31, 2010 at 21:01
  • @Charles Lee, @ColumnX is one of those (title linked by ID) columns so it does contain the ID.
    – Anonymous
    Apr 1, 2010 at 13:54
  • has anyone found a solution to this?
    – user4490
    Aug 19, 2011 at 14:49

3 Answers 3


The ID won't be there. You'll need to look up the value in the source list to get at the ID:

<xsl:variable name="LookupID" select="/dsQueryResponse/List2/Rows/Row[@Title = current()/@ColumnX]"/>
  • I'll try this approach in the XSLT, but based on what I've experienced, it seems DWVP extacts the IDs from "linked" columns.. we'll see.
    – Anonymous
    Apr 1, 2010 at 14:02
  • Without seeing your full setup, it's hard to say. Yes, the IDs are often stored so that you can access them. Apr 2, 2010 at 13:50

try the xslt function substring-before()

  • <xsl:value-of select="substring-before(@ColumnX, ';')"/> returns empty.
    – Anonymous
    Mar 31, 2010 at 20:25
  • try replacing @ColumnX with the hardcoded "12;#Bill Peet" string and see if this returns the ID. Maybe @ColumnX does not contain what you think it should contain. Can you post the full xlst? Apr 1, 2010 at 8:48
  • Thanks Jaap, but that won't work. @ColumnX must be there to obtain the real value rather than a hard coded value.
    – Anonymous
    Apr 1, 2010 at 13:41
  • I understand, but if you hardcode the value just to test, then you can tell if the problem lies with the value of @ColumnX or the result of the function. Apr 1, 2010 at 20:20
  • It's without a doubt that the ddwrt function substring-before will do its job, but that's not the problem..
    – Anonymous
    Apr 2, 2010 at 15:24

You're looking for the ID in the lookup list that relates to the textual value that is actually stored in the child list?

  • It's a column referencing to another list (Linked to item) so the ID is part of the result set when using CAML. The Data View Web Part or more specifically the XSLT should allow me to pull this value, how?
    – Anonymous
    Mar 31, 2010 at 14:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.