Copied to clipboard

Flag this post as spam?

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


  • Felix 46 posts 67 karma points
    Jul 27, 2010 @ 10:55
    Felix
    0

    XSLT shambles

    Hopefully the code below makes sense...

    Im using the tree multi list control. the code is recursing upward the tree from the current page until it finds a field named 'content' that has selected nodes within it. (the field content is of type tree multi list).

    Once it finds it, i simply loop through the selected nodes within content and check if the actual node it relates to is published or deleted, and if not then i display it.

    This works ok except now what i want to do is, keep recursing UPward if none of the nodes within the content nodes are published.

    So, the problem with the code below is, it could recurse and find a node with a content field that has data within it and it would stop there, but it doesnt quiet check if the data is published, what id like to do is additinally check if the data within it is published and if not, keep recursing upward, does this make any sense? hopefully one of you XSLT gurus will know the answer to this!

    Thanks in advance!

     

    <xsl:param name="currentPage"/>

    <xsl:template match="/">
    <xsl:variable name="dataField" select="$currentPage/ancestor-or-self::node [string(data[@alias='content'])!=''] [position()=1] /data[@alias='content']"/>
    <xsl:if test="string($dataField) != ''">
    <xsl:variable name="dataNodes" select="umbraco.library:Split($dataField, ',')"/>
    <!-- check if node is deleted or unpiblushed -->
    <xsl:for-each select="$dataNodes//value ">
    <xsl:variable name="thing" select="umbraco.library:GetXmlNodeById(.)" />
    <xsl:if test="count($thing/error) = 0">
    <xsl:value-of select="$thing/data [@alias='body']" disable-output-escaping="yes"/>
    </xsl:if>
    </xsl:for-each>
    </xsl:if>
    </xsl:template>
  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    Jul 27, 2010 @ 11:05
    Lee Kelleher
    0

    Hi Felix,

    Only published nodes are stored in the XML cache.  Unpublished nodes are not accessible via XSLT.

    Cheers, Lee.

  • Felix 46 posts 67 karma points
    Jul 28, 2010 @ 02:31
    Felix
    0

    Hi Lee,

    Thanks for your reply. The pasted code below is already checking to see if its published or deleted. If it was unpublished, the second line would return 1.My problem is i somehow need to incporporate that into the first line of code within the template match. Let me know if im still being unclear!

     

    <xsl:variable name="thing" select="umbraco.library:GetXmlNodeById(.)" />
     
    <xsl:if test="count($thing/error) = 0">
  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    Jul 28, 2010 @ 10:48
    Lee Kelleher
    0

    Hi Felix,

    Not sure that I follow.  Are you meaning to test if the nodes are unpublished for the "dataField" variable?

    Since only the published content nodes are in the XML cache, then your XSLT/XPath will only select the content nodes that have the property alias of 'content' (that isn't empty).

    Surely its better to check if a node is there, rather then its not? (i.e. in the for-each, if you want to check for "data[@alias='body']", then test for that?)

    Cheers, Lee.

  • Felix 46 posts 67 karma points
    Jul 29, 2010 @ 04:34
    Felix
    0

    Hi Lee,

    Let me give you the total picture of what im trying to achieve.

    I have a little section at the bottom of *every* page, lets call it "Related Content".

    The way Related Content should work is, it outputs a list of related nodes selected(im using a tree multi list control for picking the related nodes).

    The business rules behind Related Content is that, If the current page has related nodes sected, then output them, if it doesnt have any sected, recurse upward, till you find a page that has related nodes selected and output those.

     

    Now say i have a page with 1 Related Node, if i then go and delete that related node(the actual related node itself), then the tree multi list doesnt automatically remove the reference to that node from the pag,e, leaving the page with one item in the list still (even though this item has already been deleted/unpublished)

    So the problem is,

    <xsl:variable name="dataField" select="$currentPage/ancestor-or-self::node [string(data[@alias='content'])!=''] [position()=1] /data[@alias='content']"/>

    The line above works, cause on the front end, within the related content list, it still has one item even though that one item has actually been deleted, therefore, it doesnt recurse upward, i need it to keep recursing upward till it finds a page with at least one "published" node.

    Hopefully this helps.

    Thanks for your efforts!

     

     

  • Felix 46 posts 67 karma points
    Jul 29, 2010 @ 07:21
    Felix
    1

    i got it working by creating a recursive function :)

Please Sign in or register to post replies

Write your reply to:

Draft