Copied to clipboard

Flag this post as spam?

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


  • Andreas Kristensen 20 posts 79 karma points
    May 14, 2013 @ 10:06
    Andreas Kristensen
    0

    Apply Templates Xpath Problem

    Hi, I am loosing my mind over this problem with using template matching.

    I am trying to get all direct children(but not descendants) of my currentpage in this XSLT macro.

    However, what i get seems to be all decendants regardless of the Xpath set to child.
    Umbraco version is 4.7.0

    Please educate me :)

    <?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:umbraco.library="urn:umbraco.library" exclude-result-prefixes="umbraco.library">
     
        <xsl:output method="xml" omit-xml-declaration="yes" indent="yes" />
     
        <xsl:param name="currentPage" />
      
        <xsl:template match="/">
          <xsl:apply-templates select="$currentPage/child::*[@isDoc]" />
        </xsl:template>
     
     <!-- vis tekst indhold-->
      <xsl:template match="DKV_TekstIndhold">
          
        <xsl:variable name="mrker" select="dkvmrker" />
        <xsl:variable name="bgcolor" select="bagrundsfarve" />
        <xsl:variable name="width" select="elementHjde" />
      <xsl:variable name="height" select="elementBredde" />
      
      <div>       
         <xsl:choose
          <xsl:when test="string($mrker) = ''">
            <xsl:attribute name="class">
              element <xsl:value-of select="$bgcolor"/> tekst <xsl:value-of select="$width"/> isotope-item <xsl:value-of select="$height"/> Alle
            </xsl:attribute>
            </xsl:when>
        <xsl:otherwise>
            <xsl:attribute name="class">
              <xsl:value-of select="$bgcolor"/> tekst <xsl:value-of select="$width"/> isotope-item <xsl:value-of select="$height"/> element <xsl:value-of select="$mrker"/>
            </xsl:attribute>
          </xsl:otherwise>
       </xsl:choose>
      
           <xsl:value-of select="dkvtekst" disable-output-escaping="yes"/>
        </div>
        </xsl:template>
    <!-- tekst END -->
     
    <!-- Photos --> 
         <xsl:template match="DKV_BilledIndhold">
       
        <xsl:variable name="mrker" select="dkvmrker" />
        <xsl:variable name="bgcolor" select="bagrundsfarve" />
        <xsl:variable name="width" select="elementHjde" />
      <xsl:variable name="height" select="elementBredde" />
        <!-- build element div width avalible CMS-node classes for filtering and styling -->
        <div>       
         <xsl:choose
          <xsl:when test="string($mrker) = ''">
            <xsl:attribute name="class">
              element <xsl:value-of select="$bgcolor"/> billed <xsl:value-of select="$width"/> isotope-item <xsl:value-of select="$height"/> Alle
                </xsl:attribute>
            </xsl:when>
           <xsl:otherwise>
            <xsl:attribute name="class">
          <xsl:value-of select="$bgcolor"/> billed <xsl:value-of select="$width"/> isotope-item <xsl:value-of select="$height"/> element <xsl:value-of select="$mrker"/>
            </xsl:attribute>
          </xsl:otherwise>
        </xsl:choose>   
         
       
           <xsl:variable name="mediaID" select="dkvbilled" />
        
           <xsl:if test="string($mediaID) != ''">
              <xsl:variable name="media" select="umbraco.library:GetMedia(dkvbilled, false)" />
              <xsl:if test="string($media) != ''">
                <img style="height:inherit;width:inherit;" src="{$media/umbracoFile}" alt="{$media/altText}" />
              </xsl:if>
             
             <style="background-color:gray" class="weight">Billede af <xsl:value-of select="@nodeName"/></p>
             
        </xsl:if>
           
           
        </div>
        </xsl:template>
    <!-- Photos END --> 

     <!-- Gallery (all images from media folder, define by creating gallery doctype page under DKV_side to display on) --> 
        <xsl:template match="DKV_Galleri">
      <xsl:variable name="mediaFolderId" select="number(mediaFolderId)" />
        <xsl:variable name="thumbWidth" select="number(110)" />
        <xsl:variable name="thumbHeight" select="number(110)" />
        <xsl:variable name="mrker" select="dkvmrker" />
      <!-- Displays all images from a folder in the Media Library -->
      
      <xsl:if test="number($mediaFolderId)">

          <xsl:for-each select="umbraco.library:GetMedia($mediaFolderId, true())/Image">
            <xsl:if test="umbracoFile !=''">
             
              <!-- build element div width avalible CMS-node classes for filtering and styling -->
                     <div>
               <xsl:choose
                <xsl:when test="string($mrker) = ''">
                <xsl:attribute name="class">
                  element isotope-item Højde1 Bredde1 alle
                  </xsl:attribute>
                </xsl:when>
                <xsl:otherwise>
                <xsl:attribute name="class">
                  element isotope-item Højde1 Bredde1 <xsl:value-of select="$mrker"/>
                </xsl:attribute>
                </xsl:otherwise>
                </xsl:choose>   
              
                <class="galleri"  href="{umbracoFile}" title="{@nodeName}" rel="gallery">
                  <img src="/imageGen.ashx?image={umbraco.library:UrlEncode(umbracoFile)}&amp;width={$thumbWidth}&amp;height={$thumbHeight}" width="{$thumbWidth}" height="{$thumbHeight}" alt="{@nodeName}" title="{@nodeName}" class="thumbnail" />
                </a>
              </div>
            </xsl:if>
          </xsl:for-each>

      </xsl:if>

        </xsl:template>  
       <!-- Gallery End --> 
           
        <!-- Anything that is hidden in umbraco-navi(not published) is sent to this blank template -->
        <xsl:template match="*[umbracoNaviHide = 1]" />
     
    </xsl:stylesheet>

     

  • Chriztian Steinmeier 2726 posts 8320 karma points MVP 4x admin c-trib
    May 14, 2013 @ 10:21
    Chriztian Steinmeier
    100

    Hi Andreas,

    I guess what's happening is that there are some (or even just a single) childnode that's not matched by a template, which causes a built-in template to kick in (check this slide for a short explanation) - and this will in turn just apply templates to it's own children and so on...

    Try adding this template to see what's going on:

    <!-- Debug template - will catch any Document Type not specifically matched -->
    <xsl:template match="*[@isDoc]" priority="-1">
        <div>
            Unmatched element found: <xsl:value-of select="concat('&lt;', name(), ' id=&quot;', @id, '&quot;&gt;')" />
        </div>
    </xsl:template>

    /Chriztian

  • Andreas Kristensen 20 posts 79 karma points
    May 14, 2013 @ 10:26
    Andreas Kristensen
    0

    Thank you so much, it looks like this was the problem, got 4 unmatched elements on the first run. 

    You sir have saved me a great amount of theoretical sanity points. hell, might have saved me a keyboard since i stopped slamming my fist into it.

    Edit: Confirmed as the solution to the problem.

  • Chriztian Steinmeier 2726 posts 8320 karma points MVP 4x admin c-trib
    May 14, 2013 @ 10:43
    Chriztian Steinmeier
    0

    Awesome - keyboards can be hard to replace if you're used to a specific (now sold out model) :-)

    It's a good day, then!

    /Chriztian

  • Andreas Kristensen 20 posts 79 karma points
    May 14, 2013 @ 10:52
    Andreas Kristensen
    0

    fairly expensive to replace my keyboard at any rate, since i splurged on a dinovo edge from logitech :)

    Thanks again, this oversight on my part came to my attention just as i was preparing user-testing of content editing so this solution has really saved my ass.

  • 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