Ste
Ste

Reputation: 1136

XSLT Parsing error when using Umbraco GetMedia

I am trying to retrieve the url to an image using the GetMedia mediapicker.

The code below works fine:

<xsl:for-each select="umbraco.library:GetXmlNodeById(1123)/* [@isDoc]">
  <article>
     <img width="1822" height="600">
       <xsl:attribute name="src">
         <xsl:value-of select="umbraco.library:GetMedia(1139, 0)/umbracoFile" />
       </xsl:attribute>
     </img>
     <div class="contents">
        <h1>
          <xsl:value-of select="bannerHeading1"/>
        </h1>
      </div>
  </article>
</xsl:for-each>

However, if I replace the key line with this:

<xsl:value-of select="umbraco.library:GetMedia(bannerImage, 0)/umbracoFile" />

I get a parsing error with the exception being an OverflowException (Value was either too large or too small for an Int32), which suggests that it's not the 1139 that is being passed in.

Is there a way I can pass in the property I want? The value of "bannerImage" is 1139 as I want it to be?

Thanks for any help.

Further: This is the XML structure being returned by GetXMLNodeById:

<?xml version="1.0" encoding="utf-8" ?>
<HomepageBanner id="1141" parentID="1123" level="3" writerID="0" creatorID="0" nodeType="1124" template="1125" sortOrder="0" createDate="2013-08-12T15:53:48" updateDate="2013-08-12T15:54:18" nodeName="Members" urlName="members" writerName="admin" creatorName="admin" path="-1,1065,1123,1141" isDoc="">
  <bannerImage>1139</bannerImage>
  <bannerHeading1>Members Area</bannerHeading1>
  <bannerHeading2>..the place for all your needs</bannerHeading2>
</HomepageBanner>

Upvotes: 1

Views: 739

Answers (1)

Ste
Ste

Reputation: 1136

For anyone else trying to get an image from an item in a content folder, this is how I got it to work:

<xsl:for-each select="umbraco.library:GetXmlNodeById(1123)/* [@isDoc]">
  <article>
    <!-- Store the ID -->
    <xsl:variable name="mediaId" select="bannerImage" />
      <!-- Check the ID is numeric -->
      <xsl:if test="number($mediaId) &gt; 0">
        <xsl:variable name="mediaNode" select="umbraco.library:GetMedia($mediaId, false())" />
        <xsl:if test="string-length($mediaNode/umbracoFile) &gt; 0">
          <img src="{$mediaNode/umbracoFile}" width="1822" height="600" />
          <div class="contents">
            <h1>
              <xsl:value-of select="bannerHeading1"/>
            </h1>
          </div>
        </xsl:if>
      </xsl:if>
    </article>
</xsl:for-each>

You first need to check that the value is numeric and then, the bit that was failing me, you need to add the "/umbracoFile" part to your media node variable.

Thanks to the contributors who helped me in the right direction.

Upvotes: 2

Related Questions