Display Images from media directory using media picker not working - asp.net

I am using Umbraco v6.1.6 and what I want is simply display the images from the media directory I select using media picker.
The content of media directory is as below:
And I have created an XSLT file named ImageSlider.xslt and the content of that file are as below:
<?xml version="1.0" encoding="utf-8" ?>
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:umb="urn:umbraco.library"
exclude-result-prefixes="umb"
>
<xsl:output method="html" indent="yes" omit-xml-declaration="yes" />
<xsl:param name="currentPage" />
<xsl:template match="/">
<xsl:variable name="media" select="umb:GetMedia(1088, 0)" />
<xsl:if test="$media">
<img src="{$media/umbracoFile}" alt="{$media/altText}" />
</xsl:if>
</xsl:template>
</xsl:stylesheet>
here 1088 is the ID of the banner directory but it is not working at all. I am new to this.
Can anyone please help me ?

I'm assuming you want to select the folder and list all images underneath it. At the moment, your code is just trying to display the folder. You need something like this...
In my example, I'm using a multi-node tree picker and you can select images and folders, rendering out a csv. It will loop through it all and list out all the images
<xsl:for-each select="$source/value">
<xsl:variable name="imageId" select="number(current())" />
<xsl:if test="$imageId > 0">
<xsl:variable name="media" select="umbraco.library:GetMedia($imageId, 0)" />
<xsl:choose>
<xsl:when test="local-name($media) = 'Image'">
<xsl:call-template name="ImageBox">
<xsl:with-param name="imageId" select="$imageId"/>
</xsl:call-template>
</xsl:when>
<xsl:when test="local-name($media) = 'Folder'">
<xsl:call-template name="LoopFolders">
<xsl:with-param name="folderId" select="$imageId"/>
</xsl:call-template>
</xsl:when>
</xsl:choose>
</xsl:if>
</xsl:for-each>
</xsl:template>
<xsl:template name="LoopFolders">
<xsl:param name="folderId"/>
<xsl:variable name="media" select="umbraco.library:GetMedia($folderId, 0)" />
<xsl:variable name="alt" select="$media/#nodeName" />
<div id="gallery">
<xsl:for-each select="umbraco.library:GetMedia($folderId, true())/Image">
<xsl:call-template name="ImageBox">
<xsl:with-param name="imageId" select="number(#id)"/>
</xsl:call-template>
</xsl:for-each>
</div>
</xsl:template>
<xsl:template name="ImageBox">
<xsl:param name="imageId"/>
<xsl:if test="$imageId > 0">
<xsl:variable name="media" select="umbraco.library:GetMedia($imageId, 0)" />
<xsl:if test="$media">
<xsl:variable name="url" select="$media/umbracoFile" />
<xsl:variable name="width" select="$media/umbracoWidth" />
<xsl:variable name="height" select="$media/umbracoHeight" />
<xsl:variable name="alt" select="$media/#nodeName" />
<img src="{$url}" alt="{$alt}" width="{$width}" height="{$height}" />
</xsl:if>
</xsl:if>
</xsl:template>

Related

XML Rename node name and convert datetime to date

I have an xml file I want to both rename the element name and return the date part of the date only to produce
<!-- reference the stylesheet -->
<?xml-stylesheet type="text/xsl" href="Dates.xsl"?>
<user>
<dob>1992-02-22T00:00:00.0000000</dob>
</user>
I want to both rename the element name and return the date part of the date only to produce
<!-- reference the stylesheet -->
<?xml-stylesheet type="text/xsl" href="Dates.xsl"?>
<user>
<USER_DOB>1992-02-22</USER_DOB>
</user>
In my XSL file
To change the element name this works
<xsl:template match="dob">
<USER_DOB><xsl:apply-templates select="node()"/></USER_DOB>
</xsl:template>
To change the date this works
<xsl:template match="dob">
<xsl:copy>
<xsl:call-template name="FormatDate">
<xsl:with-param name="DateTime" select="."/>
</xsl:call-template>
</xsl:copy>
</xsl:template>
<xsl:template name="FormatDate">
<xsl:param name="DateTime" />
<xsl:variable name="date">
<xsl:value-of select="substring-before($DateTime,'T')" />
</xsl:variable>
<xsl:if test="string-length($date) != 10">
<xsl:value-of select="$DateTime"/>
</xsl:if>
<xsl:if test="string-length($date) = 10">
<xsl:value-of select="$date"/>
</xsl:if>
</xsl:template>
I need to know how to combine both changes to produce the single output element with the renamed node and the formatted date
Thanks,
Brevan
Simply have one template matching dob that does this...
<xsl:template match="dob">
<USER_DOB>
<xsl:call-template name="FormatDate">
<xsl:with-param name="DateTime" select="."/>
</xsl:call-template>
</USER_DOB>
</xsl:template>

Input string was not in a correct format from an XSLT

I'm getting the error "Server Error in '/' Application. Input string was not in a correct format." when viewing a page from Umbraco that has the XSLT below inserted.
I think it is being caused by trying to convert a string to a number in this XSLT file. Probably from this line:
<xsl:if test="string-length($rteLinkText) != 0 and string($rteLink) = number($rteLink)">
If I remove the XSLT from the page it renders fine.
I just wanted to check with anyone who knows XSLT that I wasn't missing anything obvious.
Thanks for taking a look!
Full code of the XSLT below:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xsl:stylesheet [
<!ENTITY nbsp " ">
]>
<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:import href="../xslt/globalFunctions.xslt" />
<xsl:output method="xml" omit-xml-declaration="yes"/>
<xsl:param name="currentPage"/>
<xsl:param name="rteImage" select="/macro/rteImage" />
<xsl:param name="rteText" select="/macro/rteText" />
<xsl:param name="rteAuthor" select="/macro/rteAuthor" />
<xsl:param name="rteLinkText" select="/macro/rteLinkText" />
<xsl:param name="rteLink" select="/macro/rteLink" />
<xsl:param name="rteDonationText" select="/macro/rteDonationText" />
<xsl:param name="rteDonationLinkText" select="/macro/rteDonationLinkText" />
<xsl:param name="rteDonationLink" select="/macro/rteDonationLink" />
<xsl:template match="/">
<blockquote class="quote">
<xsl:variable name="imageRaw">
<xsl:call-template name="getImageUrlfromXML">
<xsl:with-param name="mediaItemXML" select="$rteImage/Image"/>
<xsl:with-param name="height" />
<xsl:with-param name="width" select="'100'" />
</xsl:call-template>
</xsl:variable>
<xsl:if test="string-length($imageRaw) != 0">
<img class="thumbImg" src="{$imageRaw}" />
</xsl:if>
<xsl:if test="string-length($rteText) != 0">
<p>
<xsl:value-of select="$rteText"/>
</p>
</xsl:if>
<xsl:if test="string-length($rteAuthor) != 0">
<h4 class="quotee">
<xsl:value-of select="$rteAuthor"/>
</h4>
</xsl:if>
<xsl:if test="string-length($rteLinkText) != 0 and string($rteLink) = number($rteLink)">
<a class="quoteLink" href="{umbraco.library:NiceUrl($rteLink)}">
<xsl:value-of select="$rteLinkText"/>
</a>
</xsl:if>
<xsl:if test="string-length($rteDonationText) != 0 or (string-length($rteDonationLinkText) != 0 and string-length ($rteDonationLink) != 0)">
<div class="helpUs">
<xsl:if test="string-length($rteDonationText) != 0">
<h2>
<xsl:value-of select="$rteDonationText"/>
</h2>
</xsl:if>
<xsl:if test="string-length($rteDonationLinkText) != 0 and string-length($rteDonationLink) != 0">
<a href="{$rteDonationLink}" target="_blank" class="donateBtn">
<xsl:value-of select="$rteDonationLinkText"/>
</a>
</xsl:if>
</div>
</xsl:if>
</blockquote>
</xsl:template>
</xsl:stylesheet>
I think the issue is this part of your logic:
string($rteLink) = number($rteLink)
those two will never be equal, as they're different types (one numeric and one string)? It's also possible that the $rteLink variable can't be cast to a number.
Should it not be something like:
<xsl:if test="string-length($rteLinkText) != 0 and string-length($rteLink) != 0 and number($rteLink) > 0">

XSLT Informal Time Translation

I'm currently working on a translation of documents for importing as XML to another system, and this involves the translation of a quite informal representation of time, such as the following:
<estimated-time>15 mins<estimated-time>
And I need to translate this to something like the following:
<tr:estimated_time>00:15:00</tr:estimated_time>
I've messed around with tokenizing, substrings, and the various time functions and haven't been able to come up with anything, though I am quite inexperienced in XSLT.
Following Jirka's answer, I tried the following:
<xsl:template match="estimated-time">
<tr:estimated_time>
<xsl:value-of select="time:parseTime(./text(), 'hours')"/>
<xsl:text>:</xsl:text>
<xsl:value-of select="time:parseTime(./text(), 'mins')"/>
<xsl:text>:</xsl:text>
<xsl:value-of select="time:parseTime(./text(), 'seconds')"/>
</tr:estimated_time>
</xsl:template>
<xsl:function name="time:parseTime">
<xsl:param name="testedString"/>
<xsl:param name="lookingFor"/>
<xsl:variable name="tokens" select="tokenize($testedString, ' ')" />
<xsl:variable name="out">
<xsl:choose>
<xsl:when test="$tokens[. = $lookingFor]">
<xsl:variable name="pos" select="index-of($tokens, $lookingFor)-1"/>
<xsl:value-of select="$tokens[$pos]"/>
</xsl:when>
<xsl:otherwise>
<xsl:text>00</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:value-of select="if (string-length($out)=1) then concat('0', $out) else $out"/>
</xsl:function>
Which always resulted in:
<tr:estimated_time>00:00:00</tr:estimated_time>
Any assistance would be greatly appreciated.
Update: it works! There were some weird newlines all over the original that I hadn't spotted, which were preventing it from working.
Might be there is a more sofisticated or cleaner solution but using tokenizing it should be done for example in this way
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions" xmlns:tst="test">
<xsl:output method="xml" indent="yes" />
<xsl:template match="/">
<times>
<xsl:apply-templates select="times/time" />
</times>
</xsl:template>
<xsl:template match="time">
<time>
<xsl:value-of select="tst:getSomething(.,'hours')" />
<xsl:text>:</xsl:text>
<xsl:value-of select="tst:getSomething(.,'mins')" />
<xsl:text>:</xsl:text>
<xsl:value-of select="tst:getSomething(.,'sec')" />
</time>
</xsl:template>
<xsl:function name="tst:getSomething">
<xsl:param name="testedString" />
<xsl:param name="lookingFor" />
<xsl:variable name="tokens" select="tokenize($testedString, ' ')" />
<xsl:variable name="tmp">
<xsl:choose>
<xsl:when test="$tokens[. = $lookingFor]">
<xsl:variable name="pos" select="index-of($tokens, $lookingFor) - 1" />
<xsl:value-of select="$tokens[$pos]" />
</xsl:when>
<xsl:otherwise>
<xsl:text>00</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:value-of select="if (string-length($tmp) = 1) then concat('0', $tmp) else $tmp" />
</xsl:function>
</xsl:stylesheet>
It produces output
<?xml version="1.0" encoding="UTF-8"?>
<times>
<time>05:30:00</time>
<time>00:05:00</time>
</times>

Issues with publishing an RSS feed

I'm having trouble publishing an RSS feed from my Umbraco site. I found this Umbraco.TV video and tried to follow the instructions there using an XSLT selector to select all nodes of a give type, like so:
umbraco.library.GetXmlAll()/node [#nodeTypeAlias='Alias]/node
As sugested here but that didn't work. Apparently the schema has changed or something. When this didn't work I looked for a plugin to do this kind of stuff and was amazed to find just 2 plugins, both of them with little-to-no documentation and neither seemed to work (first plugin, second plugin).
So once and for all, I'd like to have a definite answer - how does one publish an RSS feed in Umbraco?
Here's an XSLT that we use for News Items RSS (News Items are under a News Page). Let me know if that helps. I also have versions for Blogs.
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:rssdatehelper="urn:rssdatehelper"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
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"/>
<!-- Update these variables to modify the feed -->
<xsl:variable name="RSSNoItems" select="/macro/RSSNoItems"/>
<xsl:variable name="RSSTitle" select="/macro/RSSTitle"/>
<xsl:variable name="SiteURL" select="concat('http://',umbraco.library:RequestServerVariables('HTTP_HOST'))"/>
<xsl:variable name="RSSDescription" select="/macro/RSSDescription"/>
<xsl:variable name="source" select="/macro/source"/>
<!-- This gets all news and events and orders by updateDate to use for the pubDate in RSS feed -->
<xsl:variable name="pubDate">
<xsl:for-each select="umbraco.library:GetXmlNodeById($source)/* [#isDoc and string(umbracoNaviHide) != '1']">
<xsl:sort select="./newsDate" order="descending" />
<xsl:if test="position() = 1">
<xsl:value-of select="./newsDate" />
</xsl:if>
</xsl:for-each>
</xsl:variable>
<xsl:template match="/">
<!-- change the mimetype for the current page to xml -->
<xsl:value-of select="umbraco.library:ChangeContentType('text/xml')"/>
<xsl:text disable-output-escaping="yes"><?xml version="1.0" encoding="UTF-8"?></xsl:text>
<rss version="2.0"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:wfw="http://wellformedweb.org/CommentAPI/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
>
<channel>
<title>
<xsl:value-of select="$RSSTitle"/>
</title>
<link>
<xsl:value-of select="$SiteURL"/>
</link>
<pubDate>
<xsl:value-of select="$pubDate"/>
</pubDate>
<generator>umbraco v4</generator>
<description>
<xsl:value-of select="$RSSDescription"/>
</description>
<language>en</language>
<xsl:for-each select="umbraco.library:GetXmlNodeById($source)/* [#isDoc and string(umbracoNaviHide) != '1']">
<xsl:sort select="./newsDate" order="descending" />
<xsl:if test="position() <= $RSSNoItems">
<xsl:call-template name="RSSitem">
<xsl:with-param name="node" select="current()"/>
</xsl:call-template>
</xsl:if>
</xsl:for-each>
</channel>
</rss>
</xsl:template>
<xsl:template match="node">
<xsl:if test="position() <= $RSSNoItems">
<item>
<title>
<xsl:value-of select="#nodeName"/>
</title>
<link>
<xsl:value-of select="$SiteURL"/>
<xsl:value-of select="umbraco.library:NiceUrl(#id)"/>
</link>
<pubDate>
<xsl:value-of select="umbraco.library:FormatDateTime(./newsDate,'r')" />
</pubDate>
<guid>
<xsl:value-of select="$SiteURL"/>
<xsl:value-of select="umbraco.library:NiceUrl(#id)"/>
</guid>
<content:encoded>
<xsl:value-of select="concat('<![CDATA[ ', ./bodyText,']]>')" disable-output-escaping="yes"/>
</content:encoded>
</item>
</xsl:if>
</xsl:template>
<xsl:template name="RSSitem">
<xsl:param name="node"/>
<item>
<title>
<xsl:value-of select="$node/#nodeName"/>
</title>
<link>
<xsl:value-of select="$SiteURL"/><xsl:value-of select="umbraco.library:NiceUrl($node/#id)"/>
</link>
<pubDate>
<xsl:value-of select="umbraco.library:FormatDateTime(./newsDate,'r')"/>
</pubDate>
<dc:creator><xsl:value-of select="#writerName"/></dc:creator>
<xsl:for-each select="umbraco.library:Split($node/categories, ',')/value">
<xsl:sort data-type="text" order="ascending"/>
<category>
<xsl:value-of select="current()"/>
</category>
</xsl:for-each>
<guid>
<xsl:value-of select="$SiteURL"/><xsl:value-of select="umbraco.library:NiceUrl($node/#id)"/>
</guid>
<description>
<xsl:value-of select="concat('<![CDATA[ ', $node/summary,']]>')" disable-output-escaping="yes"/>
</description>
<content:encoded>
<xsl:value-of select="concat('<![CDATA[ ', $node/bodyText,']]>')" disable-output-escaping="yes"/>
</content:encoded>
</item>
</xsl:template>
</xsl:stylesheet>

Trim first 10 characters off the title of RSS feed

I'm trying to write some xsl to style an RSS feed. I need to trim the first 10 characters off the title of each item.
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="/rss">
<ul>
<xsl:for-each select="channel/item">
<li><strong><xsl:value-of select="title"/>
</strong>
More</li>
</xsl:for-each>
</ul>
</xsl:template>
<xsl:template name="trimtitle">
<xsl:param name="string" select="." />
<xsl:if test="$string">
<xsl:text>Foo</xsl:text>
<xsl:call-template name="trimtitle">
<xsl:with-param name="string" select="substring($string, 10)" />
</xsl:call-template>
</xsl:if>
</xsl:template>
<xsl:template match="title">
<xsl:call-template name="title" />
<xsl:value-of select="." />
</xsl:template>
</xsl:stylesheet>
I think you should write your substring function as this:
substring($string,1, 10)
Look at here
http://www.zvon.org/xxl/XSLTreference/Output/function_substring.html
What are you doing in your trimtitle template?
Why are you calling trimtitle recursive..?
The easiest way to show a trimmed string is with:
<xsl:value-of select="substring(title,0,10)"/>

Resources