2

I have created an item template in ItemStyle.xsl to assign it to the CQWP.

My template is:

<xsl:template name="DepartmentsTemplate" match="Row[@Style='DepartmentsTemplate']" mode="itemstyle">

<xsl:variable name="DisplayTitle">
        <xsl:call-template name="OuterTemplate.GetTitle">
            <xsl:with-param name="Title" select="@Title"/>                                    
        </xsl:call-template>
    </xsl:variable>  

    <a onclick="sayHello('{@Title}')"> <xsl:value-of select="@Department" disable-output-escaping="yes"></xsl:value-of></a>
</xsl:template>

Here the value I am displaying in @Department is of type managed metadata field. It displays output like: Department 2|c98ce851-88fd-41bc-a013-4a69dd6bae66 but I want to display Department 2 only.

What should I do?

3

Try using the XSLT substring-before function:

<xsl:value-of select="substring-before(@Department,'|')" disable-output-escaping="yes">
  • Thank you sir, can you help for my this query? – users1100 Oct 30 '13 at 9:14
3

Dave's solution fixes your problem with assumption your data always contains a |. If you want to make your solution a little more robust you could also write this:

<xsl:value-of select="substring-before(concat(@Department, '|'), '|')" disable-output-escaping="yes"></xsl:value-of></a>

This will also work in the case that the string does not have a | in it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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