Copied to clipboard

Flag this post as spam?

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


  • Garrett Fisher 341 posts 496 karma points
    Oct 16, 2012 @ 18:41
    Garrett Fisher
    0

    Using Related Nodes Method

    Hi,

    Why am I getting a parsing error from this code?

        <xsl:variable name="thisVideoPage" select="umbraco.library:GetXmlNodeById($currentPage/video)"/>
        <xsl:variable name="relatedVideoPage" select="umbraco.library:GetRelatedNodesAsXml($thisVideoPage/@id)" />
      
        <xsl:variable name="video">
          <xsl:choose>
            <xsl:when test="$currentLanguage = 'English'">
              <xsl:value-of select="$thisVideoPage"/>
            </xsl:when>
            <xsl:otherwise>
              <xsl:value-of select="umbraco.library:GetXmlNodeById($relatedVideoPage/relations/relation/node/@id)"/>
          </xsl:otherwise>
          </xsl:choose>
        </xsl:variable>
      
      <xsl:value-of select="$video/@id"/>

     

    Both $thisVideoPage andf $relatedVideoPage return the correct ID, so why cant I dynamically switch out this $video object??  As soon as I output any property of the $video variable (which is supposed to be the video page object), I get an XSLT parsing error. 

    Have a page where you can select a video page from somewhere else to show, and this stores as an ID.  But thereare instances of these pages in each language so that's why I am using GetRelatedNodesAsXml().  What's wrong with this code?  Can't see any way to write the links / show the video thumb if I can't use this $video object.

    Thanks,

    Garrett

  • Sean Mooney 131 posts 158 karma points c-trib
    Oct 16, 2012 @ 19:28
    Sean Mooney
    0

    Have you tried using xsl:copy-of instead of xsl:value-of?

    <xsl:copy-ofselect="$thisVideoPage"/>

     

    and

    <xsl:copy-ofselect="umbraco.library:GetXmlNodeById($relatedVideoPage/relations/relation/node/@id)"/>

  • Garrett Fisher 341 posts 496 karma points
    Oct 16, 2012 @ 19:37
    Garrett Fisher
    0

    Yes.  Same result.  Seems to happen to me every time I put logic inside a variable.  But I can't wrap the logic around the variable declarations either, so what do I do here?  I don't want to have some gigantic logic block that does something completely different based on whether it's a related node or the main node.

    //Garrett

  • Garrett Fisher 341 posts 496 karma points
    Oct 16, 2012 @ 19:38
    Garrett Fisher
    0

    Yes.  Same result.  Seems to happen to me every time I put logic inside a variable.  But I can't wrap the logic around the variable declarations either, so what do I do here?  I don't want to have some gigantic logic block that does something completely different based on whether it's a related node or the main node.

    //Garrett

  • Sean Mooney 131 posts 158 karma points c-trib
    Oct 16, 2012 @ 20:07
    Sean Mooney
    1

    This is how I typically do it:

    <xsl:variable name="videoRaw">
      <xsl:choose>
          <xsl:when test="$currentLanguage = 'English'">
              <xsl:copy-of select="umbraco.library:GetXmlNodeById($currentPage/video)" />
          </xsl:when>
          <xsl:otherwise>
              <xsl:copy-of select="umbraco.library:GetXmlNodeById($relatedVideoPage/relations/relation/node/@id)" />
          </xsl:otherwise>
      </xsl:choose>
    </xsl:variable>
    <xsl:variable name="video" select="msxml:node-set($videoRaw)" />

    you can also use this little trick to see the xml that you have:

    <xsl:copy-of select="$video" />

     

     

  • Chriztian Steinmeier 2726 posts 8320 karma points MVP 4x admin c-trib
    Oct 16, 2012 @ 22:44
    Chriztian Steinmeier
    0

    Hi Garrett,

    The last line of Sean's 2nd reply is the key - because as soon as you "open" a variable or param declaration (thus using its contents rather than the select attribute), the result is going to be either a string (like when you were using value-of) or something called a "Result Tree Fragment" (using copy-of or literal XML nodes inside).

    Neither of those are able to be used with XPath - but the RTF variable can be converted to a node set by using the msxml:node-set() function.

    In this case it's probably possible to actually do the selection in the select attribute, but it can be a little harder to read since it'll use some tricky set logic to make the selection.  

    /Chriztian

     

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies