Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Dan 1288 posts 3921 karma points c-trib
    Apr 06, 2010 @ 14:13
    Dan
    0

    Get related content from ultimate picker data type

    Hi,

    I have a list of resource documents which, as well as appearing in the resources section of a website, can also appear in other sections on the site.  I've added an ultimate picker data type to the resource document type so the administrator can select other sections of the site for that resource to appear.  The ultimate picker data type stores these 'related nodes' as a simple comma-delimited text list.

    I'm now building a macro which can be insterted into any page on the site, which will check to see if that page has any resource documents.  Question is, how best to do the XSLT check here?  I could probably use a simple 'contains' function in XSLT to check the current node id against the ultimate picker data (adding commas before and after both strings to make sure it's comparing a whole value of course) but I wondered if there is a neater way?

    Thanks all.

  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    Apr 06, 2010 @ 14:25
    Lee Kelleher
    0

    Hi Dan,

    I wrote a blog post a while ago about how to use the Ultimate Picker data in XSLT, (scroll down to the XSLT snippet):

    http://blog.leekelleher.com/2009/09/08/umbraco-ultimate-picker-xslt-example/

    I use the umbraco.library:GetXmlNodeById() method to pull out the nodes - rather than use the "contains()" function.

    Good luck, Lee.

  • Jesper Hauge 298 posts 487 karma points c-trib
    Apr 06, 2010 @ 14:41
    Jesper Hauge
    0

    Yup I'd do the contains thing, remembering to concat with necessare commas where appropriate.

    First a couple of variables right after the currentPage parameter

    <xsl:variable name="sectionNodeId" select="$currentPage/ancestor-or-self::node[@nodeTypeAlias='section']/@id" />
    <xsl:variable name="resourceDocs" select="umbraco.library:GetXmlNodeById('resourceRootNodeId')" />
    

    Here I'm assuming that the current page can be a descendant of a section-node in your content tree, and that the resource docs is located beneath a containing node with a hardcodable id (resourceRootNodeId).

    Then an apply-templates statement in the main match section (you can do this with a for-each if you prefer)

    <xsl:apply-templates select="$resourceDocs/node[contains(concat(',',./data[@alias='sectionIds']), concat(',',$sectionNodeId,','))]" />

    Here I'm assuming the property with the multiple picker datatype is called sectionIds, the output will be a list of Id's separated with a comma, but with no preceding comma, so I've added a comma to the start of the sectionid list, to be sure I get no false positives., the second argument to the contains likewise holds the id of the section with commas around it to eliminate false positives.

    Regards
    Jesper Hauge

  • Dan 1288 posts 3921 karma points c-trib
    Apr 06, 2010 @ 15:09
    Dan
    1

    Thanks Lee and Jesper.  Jesper, that was exactly the way I thought about tackling it (I still might do it this way).  Lee, that's the other way - I thought it might be possible to split the CSV field into their own node-set but had no idea how to do this - very useful, your blog!

    Thanks both!

  • Md Johirul Islam 37 posts 57 karma points
    Sep 26, 2012 @ 17:57
    Md Johirul Islam
    0

    Hi every one i have ultimate picker name (selected bebefits and the alise name selectTheBenefits it hold the data) but in reply i did not get nothing. The code are below. I user the this link code (leekelleher.com/.../#comment-619)

    System.Xml.XmlException: The 'xsl:stylesheet' start tag on line 3 position 2 does not match the end tag of 'xsl:output'. Line 37, position 15. 
    at System.Xml.XmlTextReaderImpl.Throw(Exception e) 
    at System.Xml.XmlTextReaderImpl.Throw(String res, String[] args) 
    at System.Xml.XmlTextReaderImpl.ThrowTagMismatch(NodeData startTag) 
    at System.Xml.XmlTextReaderImpl.ParseEndElement() 
    at System.Xml.XmlTextReaderImpl.ParseElementContent() 
    at System.Xml.XmlTextReaderImpl.Read() 
    at System.Xml.Xsl.Xslt.XsltInput.ReadNextSibling() 
    at System.Xml.Xsl.Xslt.XsltInput.MoveToNextSibling() 
    at System.Xml.Xsl.Xslt.XsltLoader.LoadInstructions(List`1 content, InstructionFlags flags) 
    at System.Xml.Xsl.Xslt.XsltLoader.LoadContent(Boolean hasSelect) 
    at System.Xml.Xsl.Xslt.XsltLoader.XslVarPar() 
    at System.Xml.Xsl.Xslt.XsltLoader.LoadGlobalVariableOrParameter(NsDecl stylesheetNsList, XslNodeType nodeType) 
    at System.Xml.Xsl.Xslt.XsltLoader.LoadRealStylesheet() 
    at System.Xml.Xsl.Xslt.XsltLoader.LoadDocument() 
    at System.Xml.Xsl.Xslt.XsltLoader.LoadStylesheet(XmlReader reader, Boolean include)

    The above error show. then i modify after that no result come. Please help me. to seperate the value from ultimate picker check box list. Thank you.

     

     

     


    xsl:stylesheet [  ]>
    <xsl:stylesheet 
      version="1.0" 
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform
      xmlns:msxml="urn:schemas-microsoft-com:xslt" 
      xmlns:umbraco.library="urn:umbraco.library" xmlns:Exslt.ExsltCommon="urn:Exslt.ExsltCommon" xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes" xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath" xmlns:Exslt.ExsltRegularExpressions="urn:Exslt.ExsltRegularExpressions" xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings" xmlns:Exslt.ExsltSets="urn:Exslt.ExsltSets" xmlns:PS.XSLTsearch="urn:PS.XSLTsearch" 
      exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets PS.XSLTsearch ">

    <xsl:output method="xml" omit-xml-declaration="yes"/>

    <xsl:param name="currentPage"/>

    <xsl:template match="/">

    <xsl:variable name="preNodes">
    <xsl:variable name="relatedContent" select="$currentPage/*[@id=1098]/*[@alias='selectTheBenefits']" />
    <xsl:variable name="nodeIds" select="umbraco.library:Split($relatedContent, ',')" />
    <xsl:for-each select="$nodeIds/value">

      <textarea>
        <xsl:copy-of select="$relatedContent" />
    textarea>
    <xsl:copy-of select="umbraco.library:GetXmlNodeById(.)"/>
    xsl:for-each>
    xsl:variable>
    <xsl:variable name="nodes" select="msxml:node-set($preNodes)/node" />

    <xsl:if test="count($nodes) > 0">

    <div class="related-content">
    <h3>Related Contenth3>
    <ul>
                        <xsl:for-each select="$nodes">
        <li>
                                <href="{umbraco.library:NiceUrl(@id)}">
                                    <xsl:value-of select="@nodeName">
                                xsl:value-of>a>li>
    xsl:for-each>ul>
    div>

    xsl:if>

    xsl:template>

    xsl:stylesheet>

Please Sign in or register to post replies

Write your reply to:

Draft