SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How can I match on multiple fieldrefs?

I've made a copy of fldtypes.xsl in the /_layouts/xsl/ directory where I can work with fields in my lists (I have to restart the web application to get it to take).

Now, I have this routine which will convert the text in a field into an icon by changing the display value of the field by adding some custom css classes (that supply the icons).

My problem is that I want to use this same template on more than one field ref. This one will run on any column in my portal with the title of Yes or No Column, but I want it to match also on another column entitled Approval.

    <!-- Convert the Fields into a status icons    -->  
    <xsl:template match="FieldRef[@Name='Yes or No Column']" mode="body">
        <xsl:param name="thisNode" select="."/>
        <xsl:variable name="currentValue" select="$thisNode/@Yes_x0020_or_x0020_No_x0020_Column" />
        <xsl:variable name="yes">Yes</xsl:variable>
        <xsl:variable name="no">No</xsl:variable>

            <xsl:when test="contains($currentValue, $yes)">
                <span class="yesno yes"></span>
            <xsl:when test="contains($currentValue, $no)">
                <span class="yesno no"></span>
                <span><xsl:value-of select="$currentValue" /></span>

So how can I use the same template on mutliple fieldrefs?

share|improve this question
up vote 0 down vote accepted

The answer was actually simple to get the match on two different fields:

<xsl:template match="FieldRef[@Name='YesNo1']|FieldRef[@Name='YesNo2']" mode="body">

You just separate the elements with a '|' and still use the FieldRef.

That's it.

For choice fields, the mode will always be body, by the way.


Ha ha - I asked a similar question in Stack Exchange and forgot about it. Well, now the answer is in Sharepoint Stack Exchange, too.

In order to fetch the value of the current field into a variable, do this:

<xsl:variable name="currentValue" select="$thisNode/@*[name()=current()/@Name]" />

There are some other examples of how to match multiple fields here.

Also, since it is related, if you need to test multiple values (and you are using <xsl:choose> - you can do use both and and or in the test!

<xsl:when test="contains($currentValue, 'false') and contains($currentValue,'no'">
    <!--do something-->


<xsl:when test="$currentValue='Yes' or $currentValue='yes' or $currentValue='True' or $currentValue='true' ">
    <!--do something-->
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.