Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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:choose>
            <xsl:when test="contains($currentValue, $yes)">
                <span class="yesno yes"></span>
            </xsl:when>
            <xsl:when test="contains($currentValue, $no)">
                <span class="yesno no"></span>
            </xsl:when> 
            <xsl:otherwise>
                <span><xsl:value-of select="$currentValue" /></span>
            </xsl:otherwise>                    
        </xsl:choose>
    </xsl:template> 

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

share|improve this question

1 Answer 1

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.

[edit]

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> 

or:

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

Your Answer

 
discard

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.