Copied to clipboard

Flag this post as spam?

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


  • Anthony Candaele 1197 posts 2049 karma points
    Mar 10, 2011 @ 10:38
    Anthony Candaele
    0

    problem with xslt

    Hi, I guess I'll never be good at Xslt.

    I created a property (boekentips) of datatype contentpicker.

    Now in my xslt-file I just want to create a link to the page that the user has chosen with the content picker.

    My xslt looks something like this:

    <xsl:param name="currentPage"/>
    <xsl:variable name="boekentips" select="umbraco.library:GetXmlNodeById($currentPage/boekentips)" />
        <xsl:variable name="id" select="boekentips/@id" />    
    <xsl:template match="/">
      <xsl:element name="a">
        <xsl:attribute name="href">
          <xsl:copy-of select="umbraco.library:NiceUrl($id)"/>
        </xsl:attribute>
      </xsl:element>
    </xsl:template>

    But, as you one would imagine this doesn't work.

    the line

    <xsl:variable name="boekentips" select="umbraco.library:GetXmlNodeById($currentPage/boekentips)" />

    does generate the xml-node of the chosen page, but when I use the variable $boekentips to create a link, like $boekentips/id I get the following error message in the xslt-viewer:

    "System.Xml.Xsl.XslLoadException: The variable or parameter 'id' is either not defined or it is out of scope."

    Can someone help me, all I need to do is create a link to the page that was chosen with the content picker.

    Thanks for your help,

    Anthony

  • Anthony Candaele 1197 posts 2049 karma points
    Mar 10, 2011 @ 11:01
    Anthony Candaele
    0

    I solved the problem partially, I changed my xslt-code to this:

    <xsl:variable name="boekentips" select="umbraco.library:GetXmlNodeById($currentPage/boekentips)" />
    <xsl:template match="/">
      <a href="{umbraco.library:NiceUrl($boekentips/@id)}"><xsl:value-of select="$boekentips/@nodeName" /></a>
    </xsl:template>

    And this works, but only for the homepage. If I go to a page under the homepage I get this error:

    Error parsing XSLT file: \xslt\GetBoekentips.xslt

     

  • Michael Latouche 504 posts 819 karma points MVP 4x c-trib
    Mar 10, 2011 @ 11:26
    Michael Latouche
    1

    Hi Anthony,

    I am not an xslt expert either, but have you tried  your initial xslt by using $boekentips/@id instead of boekentips/@id to fill in your "id" variable. So, something like this:

    <xsl:param name="currentPage"/>
    <xsl:variable name="boekentips" select="umbraco.library:GetXmlNodeById($currentPage/boekentips)"/>
    <xsl:variable name="id" select="$boekentips/@id" />    
    <xsl:template match="/">
      <xsl:element name="a">
        <xsl:attribute name="href">
          <xsl:copy-of select="umbraco.library:NiceUrl($id)"/>
        </xsl:attribute>
      </xsl:element>
    </xsl:template>

    Hope this helps.

    Cheers,

    Michael.

  • Kim Andersen 1447 posts 2197 karma points MVP
    Mar 10, 2011 @ 11:35
    Kim Andersen
    1

    Hi Anthony

    Do you have the content picker on each page of your site or just the homepage?

    If you've got it on every page try this:

    <xsl:if test="$currentPage/boekentips!=''">   
    <xsl:variable name="boekentips" select="umbraco.library:GetXmlNodeById($currentPage/boekentips)"/>
    <a href="{umbraco.library:NiceUrl(
    $currentPage/boekentips)}"><xsl:value-of select="$boekentips/@nodeName" /></a>
    </xsl:if>

    /Kim A

  • Anthony Candaele 1197 posts 2049 karma points
    Mar 10, 2011 @ 11:37
    Anthony Candaele
    0

    Hi Michael,

    I already solved the problem partially, my xslt-code looks like this now:

    <xsl:variable name="boekentips" select="umbraco.library:GetXmlNodeById($currentPage/boekentips)" />
        <xsl:template match="/">
      <a href="{umbraco.library:NiceUrl($boekentips/@id)}"><xsl:value-of select="$boekentips/@nodeName" /></a>
    </xsl:template>

    The only problem I still have is that this only works on my homepage, the boekentips property is defined on the homepage document type.

    But if I go to a page that is a child of the homepage I get the error:

    Error parsing XSLT file: \xslt\GetBoekentips.xslt

    Thanks for your help (again),

    Anthony

  • Anthony Candaele 1197 posts 2049 karma points
    Mar 10, 2011 @ 11:39
    Anthony Candaele
    0

    @Kim: I only got the boekentips property defined on my homepage document type.

    Thanks for your help,

    Anthony

  • Michael Latouche 504 posts 819 karma points MVP 4x c-trib
    Mar 10, 2011 @ 11:49
    Michael Latouche
    0

    Hi Anthony,

    Just to make sure I understand what you are trying to do:

    1/ You have a "boekentips" property defined on your homepage document type only

    2/ You want to display the "boekentips" link only on the homepage and you get an error on sub-pages
    OR
    2 bis/ You want to display the boekentips link on all pages but it only works on the homepage.

    Another question: Do you get anything else then "Error parsing XSLT file: \xslt\GetBoekentips.xslt". Maybe some indication on where it has problems?

    Cheers,

    Michael.

  • Anthony Candaele 1197 posts 2049 karma points
    Mar 10, 2011 @ 11:54
    Anthony Candaele
    0

    Hi Michael,

    it's 2 bis :)

    I define the boekentips property on my homepage document type, but it should show on all child pages under my homepage.

    I have adapted a little the code snippet of Kim by using an XPath axis, like this:

    <xsl:template match="/">
      <xsl:if test="ancestor-or-self::boekentips!=''">   
        <xsl:variable name="boekentips" select="umbraco.library:GetXmlNodeById($currentPage/boekentips)"/>
        <a href="{umbraco.library:NiceUrl($currentPage/boekentips)}"><xsl:value-of select="$boekentips/@nodeName" /></a>
    </xsl:if>

    </xsl:template>

    but it doesn't work

  • Michael Latouche 504 posts 819 karma points MVP 4x c-trib
    Mar 10, 2011 @ 12:13
    Michael Latouche
    0

    Hi Anthony,

    It is in fact possible to identify the document type name by using the name() method. So maybe you might try something like this:

    <xsl:variable name="homepage" select="$currentPage/ancestor-or-self::* [name()='YOUR_DOCTYPE_ALIAS']"
    <
    xsl:template match="/">
      <xsl:if test="$homepage/boekentips!=''">   
        <xsl:variable name="boekentips" select="umbraco.library:GetXmlNodeById($homepage/boekentips)"/>
        <a href="{umbraco.library:NiceUrl($homepage/boekentips)}"><xsl:value-of select="$boekentips/@nodeName" /></a>
    </xsl:if>
    </xsl:template>

     

    Hope this helps/works :-)

    Cheers,

    Michael.


  • Kim Andersen 1447 posts 2197 karma points MVP
    Mar 10, 2011 @ 12:43
    Kim Andersen
    1

    Okay.

    Let's say that your homepage is located on level 1, then you should be able to do like this:

    <xsl:variable name="home" select="$currentPage/ancestor-or-self::*[@level='1']" />
    <xsl:if
    test="$home/boekentips!=''">  
        <xsl:variable name="boekentips" select="umbraco.library:GetXmlNodeById($home/boekentips)"/>
       
    <a href="{umbraco.library:NiceUrl(
    $home/boekentips)}"><xsl:value-of select="$boekentips/@nodeName" /></a>
    </xsl:if>

    Or you could also grab the homepage by it's document type like this (if the document type of the homepage is called Homepage):

    <xsl:variable name="home" select="$currentPage/ancestor-or-self::Homepage" />

    /Kim A

  • Anthony Candaele 1197 posts 2049 karma points
    Mar 10, 2011 @ 13:39
    Anthony Candaele
    0

    Hi Kim,

    I tried your code example and it works, thanks a lot!

    Anthony

  • Kim Andersen 1447 posts 2197 karma points MVP
    Mar 10, 2011 @ 14:52
    Kim Andersen
    0

    I'm glad to hear that Anthony. You are very welcome.

    /Kim A

  • 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.

    Continue discussion

Please Sign in or register to post replies