Copied to clipboard

Flag this post as spam?

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


  • MartinB 411 posts 512 karma points
    Aug 16, 2010 @ 11:54
    MartinB
    0

    Pass doctype value to url in Xslt

    Hi

    I'm using an accordion menu that can handle a simple "?expandable=[number]" parameter. I want to pass that value in my menu through a doctype property. The number value changes and i want to control i manually.

    I had it working by setting it on the href xsl attribute, but that only worked when i was on that specific page and reloaded it ($currentPage/expandableUrl). Then the url was correct. So somehow i need to pass it into my for-each loop (i guess) so my "parameter" gets indexed immediately and always present on my <li>'s when filled in.

    How do i go about it?

    Clean Xslt:

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE xsl:stylesheet [
    <!ENTITY nbsp "&#x00A0;">
    ]>
    <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"
    exclude-result-prefixes="msxml umbraco.library">


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

    <xsl:param name="currentPage"/>

    <!-- Input the documenttype you want here -->
    <xsl:variable name="level" select="1"/>

    <xsl:template match="/">

    <!-- The fun starts here -->
    <ul id="topnavigation">
    <xsl:for-each select="$currentPage/ancestor-or-self::* [@level = $level]/* [string(umbracoNaviHide) != '1' and @isDoc]">
    <li>
    <a href="{umbraco.library:NiceUrl(@id)}">
    <xsl:if test="$currentPage/@nodeName = current()/@nodeName">
    <xsl:attribute name="class">selected</xsl:attribute>
    </xsl:if>
    <xsl:value-of select="@nodeName"/>

    </a>
    </li>
    </xsl:for-each>
    </ul>

    </xsl:template>

    </xsl:stylesheet>
  • Anders Burla 2560 posts 8256 karma points
    Aug 16, 2010 @ 12:13
    Anders Burla
    0

    Could you write an examle of the html you want? And maybe for 2 different pages so i can see the difference of the html ( if there is any )

  • MartinB 411 posts 512 karma points
    Aug 16, 2010 @ 12:32
    MartinB
    0

    Hi Anders

    Sure, or i can try to examplify it more in depth:

    I have 4 "main" pages, on each i sell a different product.On each page i have the same accordion menu, but i need a different menu-item expanded on each of these pages.

    So it would look something like this if it worked like i want it to;

    Product page 1 (href="pagename.aspx?expandable=0")
      - Subpage to Productpage 1 - same expandable parameter

    Product page 2 (href="pagename.aspx?expandable=4")
      - Subpage to Productpage 2 - same expandable parameter

    Product page 3 (href="pagename.aspx?expandable=5")
      - Subpage to Productpage 3 - same expandable parameter

    and so forth..

    My frontpage href should look like: www.mysite.dk/pagename.aspx?expandable=0

    Hope that clarifies my original post

  • MartinB 411 posts 512 karma points
    Aug 16, 2010 @ 12:35
    MartinB
    0

    My first post regarding the <li> thing might be a bit misleading. Of course i want the parameter set for the <a> tag, so the parameter gets called when i click a menu link

  • Anders Burla 2560 posts 8256 karma points
    Aug 16, 2010 @ 12:43
    Anders Burla
    0

    Could you traverse up the xml tree until you find a node with the expandableUrl property and use it at the a tag?

    Like

    menuItem/ancestor-or-self::* [./expandableUrl][1]/expandableUrl

  • MartinB 411 posts 512 karma points
    Aug 16, 2010 @ 13:07
    MartinB
    0

    Hi anders

    Actually i don't want to go up or down the three for that value. And i can see now that's my main problem.

    The Xslt below works, but sets all hrefs according to the currentPage parameter value. So i guess i just need an if statement if the parameter field is empty, then it should not output the paramete value-of.

    I'll try to fix it after lunch

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE xsl:stylesheet [
    <!ENTITY nbsp "&#x00A0;">
    ]>
    <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"
    exclude-result-prefixes="msxml umbraco.library">


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

    <xsl:param name="currentPage"/>

    <!-- Input the documenttype you want here -->
    <xsl:variable name="level" select="1"/>
    <xsl:variable name="expanded" select="$currentPage/expandedUrl"/>

    <xsl:template match="/">

    <!-- The fun starts here -->
    <ul id="topnavigation">
    <xsl:for-each select="$currentPage/ancestor-or-self::* [@level = $level]/* [string(umbracoNaviHide) != '1' and @isDoc]">
    <li>
    <a>
    <xsl:attribute name="href">
    <xsl:value-of select="umbraco.library:NiceUrl(@id)" /><xsl:value-of select="$expanded" />
    </xsl:attribute>
    <xsl:if test="$currentPage/@nodeName = current()/@nodeName">
    <xsl:attribute name="class">selected</xsl:attribute>
    </xsl:if>
    <xsl:value-of select="@nodeName"/>

    </a>
    </li>
    </xsl:for-each>
    </ul>

    </xsl:template>

    </xsl:stylesheet>
  • MartinB 411 posts 512 karma points
    Aug 16, 2010 @ 14:16
    MartinB
    0

    hmm this proved a bit more of a task than i seem able to handle :/

    If i set the property of my frontpage to have ?expandable=0 to open the first accordion menu item, then the rest of my menu items will have the same url.

    How do i get the other node parameter values to override that of currentPage?

    <xsl:if... isn't really working out for me

     

  • MartinB 411 posts 512 karma points
    Aug 16, 2010 @ 14:16
    MartinB
    0

    current xslt:

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE xsl:stylesheet [
    <!ENTITY nbsp "&#x00A0;">
    ]>
    <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"
    exclude-result-prefixes="msxml umbraco.library">


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

    <xsl:param name="currentPage"/>

    <!-- Input the documenttype you want here -->
    <xsl:variable name="level" select="1"/>
    <xsl:variable name="expanded" select="$currentPage/expandedUrl"/>

    <xsl:template match="/">

    <!-- The fun starts here -->
    <!--<textarea>
    <xsl:copy-of select="$expanded" />
    </textarea>-->

    <ul id="topnavigation">
    <xsl:for-each select="$currentPage/ancestor-or-self::* [@level = $level]/* [string(umbracoNaviHide) != '1' and @isDoc]">
    <li>
    <a>
    <xsl:attribute name="href">
    <xsl:choose>
    <xsl:when test="$expanded/node[@nodeTypeAlias != 'expanded']">
    <xsl:value-of select="umbraco.library:NiceUrl(@id)" /><xsl:value-of select="$expanded" />
    </xsl:when>
    <xsl:otherwise>
    <xsl:value-of select="umbraco.library:NiceUrl(@id)" />
    </xsl:otherwise>
    </xsl:choose>

    </xsl:attribute>
    <xsl:if test="$currentPage/@nodeName = current()/@nodeName">
    <xsl:attribute name="class">selected</xsl:attribute>
    </xsl:if>
    <xsl:value-of select="@nodeName"/>

    </a>
    </li>
    </xsl:for-each>
    </ul>

    </xsl:template>

    </xsl:stylesheet>

     

  • MartinB 411 posts 512 karma points
    Aug 16, 2010 @ 14:39
    MartinB
    0

    Alright.

    Got i solved with a bit of extra forum reading :-)

    For future usage (if any would ever do this).

    1. Make a property (mine is called "expandedUrl" without the "")

    2. Use following XSLT:

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE xsl:stylesheet [
    <!ENTITY nbsp "&#x00A0;">
    ]>
    <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"
    exclude-result-prefixes="msxml umbraco.library">


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

    <xsl:param name="currentPage"/>

    <!-- Input the documenttype you want here -->
    <xsl:variable name="level" select="1"/>

    <xsl:template match="/">

    <!-- The fun starts here -->
    <!--<textarea>
    <xsl:copy-of select="$expanded" />
    </textarea>-->

    <ul id="topnavigation">
    <xsl:for-each select="$currentPage/ancestor-or-self::* [@level = $level]/* [string(umbracoNaviHide) != '1' and @isDoc]">
    <li>
    <a>
    <xsl:attribute name="href">
    <xsl:choose>
    <xsl:when test="expandedUrl != '' ">
    <xsl:value-of select="umbraco.library:NiceUrl(@id)" /><xsl:value-of select="expandedUrl" />
    </xsl:when>
    <xsl:otherwise>
    <xsl:value-of select="umbraco.library:NiceUrl(@id)" />
    </xsl:otherwise>
    </xsl:choose>

    </xsl:attribute>
    <xsl:if test="$currentPage/@nodeName = current()/@nodeName">
    <xsl:attribute name="class">selected</xsl:attribute>
    </xsl:if>
    <xsl:value-of select="@nodeName"/>
    </a>
    </li>
    </xsl:for-each>
    </ul>
    </xsl:template>

    </xsl:stylesheet>

  • 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