Problems with GetMedia in XSLT Options
anderstollestrup
Posted: Sunday, June 22, 2008 2:19:43 PM

Rank: Newbie

Joined: 3/19/2008
Posts: 17
Location: Klokkerholm, Denmark
Hi

I'm a totally newbie in umbraco and XSLT, but now i'm able to list subpages and would like to add a image for each subpage.

The subpage documenttype contains a Media Picker property, which hold the image from the media section in umbraco.

My original XSLT goes like this:
Code:
<?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"/>

<!-- Don't change this but create a 'number' element in your -->
<!-- macro with the alias of 'numberOfItems' -->
<xsl:variable name="numberOfItems" select="/macro/numberOfItems"/>

<xsl:template match="/">

<!-- The fun starts here -->

<xsl:for-each select="$currentPage/descendant-or-self::node [@nodeTypeAlias = 'dtDog' and string(data [@alias='umbracoNaviHide']) != '1']">
  <xsl:if test="position() &lt;= $numberOfItems">
    <xsl:call-template name="listpost">
      <xsl:with-param name="node" select="."/>
    </xsl:call-template>
  </xsl:if>
</xsl:for-each>

</xsl:template>

<xsl:template name="listpost">
 
  <xsl:param name="node"/>
  <div class="dogitem">
    <h2>
      <a href="{umbraco.library:NiceUrl($node/@id)}" rel="bookmark" title="{$node/@nodeName}"><xsl:value-of select="$node/@nodeName"/></a>
    </h2>
    <xsl:value-of select="$node/data [@alias = 'pIntroText']" disable-output-escaping="yes"/>
  </div>
    
</xsl:template>

</xsl:stylesheet>


The XSLT render correct and display my subpages (see it here: http://bernercairn.dk/vores-hunde.aspx), but when I add the follwing code in listpost template, I get a XSLT error in the frontend:

Code:
<xsl:element name="img">
        <xsl:attribute name="src">
            <xsl:value-of select="umbraco.library:GetMedia($node/data[@alias='pIntroImage'], 'false')/data [@alias = 'umbracoFile'"/>
        </xsl:attribute>
</xsl:element>


What am I doing wrong ??

/Anders
tkahn
Posted: Sunday, June 22, 2008 9:18:14 PM

Rank: Fanatic

Joined: 11/24/2006
Posts: 322
Location: Stockholm, Sweden
Perhaps you could try checking if pIntroImage has a value or not (if an image is picked or not) before making the call to GetMedia? I'm thinking just a simple if-statement.

If your script makes it through the XSLT-editor in the backend without generating an error it's probably not an XSLT error but rather something that happens when it starts processing data "for real" when used.



Web Developer at Kärnhuset - http://www.karnhuset.net - Stockholm, Sweden
anderstollestrup
Posted: Monday, June 23, 2008 4:05:04 PM

Rank: Newbie

Joined: 3/19/2008
Posts: 17
Location: Klokkerholm, Denmark
Hi Thomas

Thanks for the hint. Yes, only one of the items had the Media Picker property set to an image. This code (taken from Tony Maynard-Smith's "Diary of a newbody" book on umbraco.org) solved the problem:

Code:
<xsl:if test="string($node/data [@alias='pIntroImage']) != '' ">
  <xsl:element name="img">
    <xsl:attribute name="src">
      <xsl:value-of select="umbraco.library:GetMedia($node/data [@alias='pIntroImage'], 'false')/data [@alias = 'umbracoFile']"/>
      </xsl:attribute>
    </xsl:element>
</xsl:if>


Well, the support from the umbraco community is way better than the professional support offered the Dynamicweb Partners. Thumbs-up !!

/Anders

Note: Dynamicweb is the leading CMS vendor in Denmark in the lower-middle market.
Users browsing this topic
Guest


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.