Copied to clipboard

Flag this post as spam?

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


  • Bruce Canino 21 posts 42 karma points
    Apr 29, 2011 @ 00:15
    Bruce Canino
    0

    Repeteable Custom Contorl XSLT for ancestors

    I have a repetable custon control 2.0 for which I am trying to modifed to pick up the current page or ancestors page to get the data, It mostly works. It works for the first page that has data and it works for any child who don't have data, but when I have a second child that has data, it picks up the data from higher up in the list. I tried playing with node and root instand of * for ancestor-or-self but they don't work. I guess I still don't understand fully how ancestor-or-self works.

    the data

          <buttonNav>
            <items>
              <item>
                <data alias="button">1116</data>
                <data alias="url">/solutions/sol-ppo-network.aspx</data>
              </item>
              <item>
                <data alias="button">1115</data>
                <data alias="url">/solutions/sol-medical-bill-review.aspx</data>
              </item>
              <item>
                <data alias="button">1117</data>
                <data alias="url">/solutions/sol-case-management.aspx -</data>
              </item>
              <item>
                <data alias="button">1123</data>
                <data alias="url">/solutions/sol-nj-auto-precert.aspx</data>
              </item>
              <item>
                <data alias="button">1124</data>
                <data alias="url">/solutions/sol-aims.aspx</data>
              </item>
            </items>
          </buttonNav>

    the 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" 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"
      exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets ">


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

    <xsl:param name="currentPage"/>

          <!-- Input the repeatable custom contents property alias here -->
      <xsl:variable name="propertyAlias" select="string('buttonNav')"/>

    <xsl:template match="/">

    <!-- start writing XSLT -->
      <div id="buttons">
        <xsl:for-each select="$currentPage/ancestor-or-self::* /buttonNav[1]/items/item">
            <xsl:if test="position() = 1">
              <h3>Learn More:</h3>  
            </xsl:if>
            <p>
              <xsl:element name="a">
                    <xsl:attribute name="href">
                      <xsl:value-of select="./data [@alias = 'url']" disable-output-escaping="yes"/>
                    </xsl:attribute>
                    <xsl:element name="img">
                      <xsl:attribute name="src">
                        <xsl:value-of select="umbraco.library:GetMedia(./data [@alias = 'button'], 0)/umbracoFile" />
                      </xsl:attribute>
                </xsl:element>   
              </xsl:element>

            </p>
          </xsl:for-each>

          <!-- Live Editing support for related links. -->
        <xsl:value-of select="umbraco.library:Item($currentPage/@id,$propertyAlias,'')" />
        </div>
    </xsl:template>

    </xsl:stylesheet>

     

  • Bruce Canino 21 posts 42 karma points
    Apr 29, 2011 @ 09:15
    Bruce Canino
    0

    As a update, fooling around I changed the select line to:

     

        <xsl:for-each select="$currentPage/ancestor-or-self::* /buttonNav/items/item">

    and now not only does it get the closest node, but all the nodes.

    What I want is the closest not empty node

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Apr 29, 2011 @ 14:19
    Tom Fulton
    0

    Not tested, but maybe try this:

    $currentPage/ancestor-or-self::* [@isDoc][count(./buttonNav/items/item) &gt; 0]

    -Tom

  • Bruce Canino 21 posts 42 karma points
    Apr 29, 2011 @ 22:38
    Bruce Canino
    0

    Thanks for the try, nothing shows up on pages where buttonNav doesn't have any entires but all I get is

    Error parsing XSLT file: \xslt\buttonNav.xslt

    for pages that have buttonNav entires.

  • Chriztian Steinmeier 2800 posts 8791 karma points MVP 8x admin c-trib
    Apr 29, 2011 @ 23:49
    Chriztian Steinmeier
    1

    Hi Bruce,

    Take a look at this visualization of the ancestor-or-self:: axis - you get a set of nodes back, as you can see.

    To get the closest ancestor with a value in the buttonNav property, you add a so-called predicate to specify that the nodes in the set should have a non-empty "buttonNav" property; and then you take the first from that set - like this:

    <xsl:variable name="navFromAncestor" select="$currentPage/ancestor-or-self::*[normalize-space(buttonNav)][1]" />

    Then you can do stuff with that - but it's important that you include the [1] filter right away (and not inside the <for-each> as you did) because the nodes will be in "document order" when you access them from the variable...

    So since the variable now points to the ancestor(or self) you can iterate or appy, whichever suits you, e.g.:

    <xsl:for-each select="$navFromAncestor/buttonNav/items/item">
        <!-- do stuff -->
    </xsl:for-each> 

    /Chriztian 

  • Bruce Canino 21 posts 42 karma points
    Apr 30, 2011 @ 18:58
    Bruce Canino
    0

    Chriztian,

    That code change makes it work as I want it to.

    Thank you very much for your explanation of ancestor-or-self. The visualization link was very helpful.

    Bruce

     

Please Sign in or register to post replies

Write your reply to:

Draft