|
|
Rank: Newbie
Joined: 12/5/2007 Posts: 6
|
I have added an image through the Media icon (next to the Content icon). Obviously this media item does not appear in the document (through $currentPage and it's ancestors) as it isn't related to any page within the current site (its parentId = -1 and level = 1).
Is there any way to retrieve the xml for this node in the DB so I can use it in my XLST? I won't necessarily know the id at runtime so can't use the GetMedia(int MediaId, bool Deep) library function. All I have is the name of the media item (nodeName).
Getting very frustrated :cry:
|
|
 Rank: Umbracoholic
Joined: 7/20/2006 Posts: 1,074 Location: Charleston, West Virginia, United States
|
Hi Sean, While you could potentially use GetItem and search the entire tree for the media item by name, the end result would be terribly slow, as the media section is not cached the same way the content section is. You can use a media picker control on the content page (as a document type property) to associate the media item with that node, and then use that in your xslt to retrieve the media information. Hope this helps, Case
• 2007/2008 MVP • 2008/2009 MVP • Certified • Licensing • Support • Development • Hosting •
|
|
Rank: Newbie
Joined: 12/5/2007 Posts: 6
|
Hi Casey,
Thanks - did as you suggested and have it working.
I have a previous unanswered question on cross-referencing pages. Any chance you could take a stab at it?
Cheers, Sean
|
|
Rank: Newbie
Joined: 9/14/2006 Posts: 9
|
Hi, I'm trying to do the same thing but when I return the information about the photo from XSLT, I get ALL of the information in one string: Code:/media/278/lesley.jpg971465089jpg The first bit is the URL (/media/278/lesley.jpg), then width (97), height (146), size and format. How do I pull each of these bits of information out separately?? In particular the URL. I'm using Umbraco 3, and the photo is being chosen by a MediaCurrent. Any help would be much appreciated!
|
|
 Rank: Umbracoholic
Joined: 9/8/2006 Posts: 1,698 Location: KY, USA
|
Hi, Rachel, Try something like this to get just the filename portion... Code: <xsl:value-of select="umbraco.library:GetMedia($photo, false)/data [@alias = 'umbracoFile']"/>
I'm using a variable called $photo in my example, but I hope you get the idea and can adapt it to your needs. The key is to look inside the /data [@alias='umbracoFile'] rather than the whole node. cheers, doug.
MVP 2007-2009 - Official Umbraco Trainer for North America - Percipient Studios
|
|
Rank: Newbie
Joined: 9/14/2006 Posts: 9
|
Thanks so much for replying Doug, but I'm afraid I am a beginner at XSLT and I can't make sense of your example... This is the code I have so far: Code:<?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: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"/>
<xsl:template match="/">
<xsl:variable name="team_name" select="/macro/team_name" /> <xsl:variable name="team_position" select="/macro/team_position" /> <xsl:variable name="team_description" select="/macro/team_description" /> <xsl:variable name="team_phone" select="/macro/team_phone" /> <xsl:variable name="team_email" select="/macro/team_email" /> <xsl:variable name="team_photo" select="/macro/team_photo"/> <!-- start writing XSLT --> <div class="team"> <h3><xsl:value-of select="/macro/team_name" /> - <xsl:value-of select="/macro/team_position" /> <img src="photourltogohere" alt="Photo of {/macro/team_name}" title="{/macro/team_name}" /></h3> <p>Trying to get the photo URL: <xsl:value-of select="/macro/team_photo" /></p> <p><xsl:value-of select="/macro/team_description" /></p> <p><strong>Phone:</strong> <xsl:value-of select="/macro/team_phone" /><br /> <strong>Email:</strong> <a href="mailto:{/macro/team_email}"><xsl:value-of select="/macro/team_email" /></a></p> </div>
</xsl:template>
</xsl:stylesheet> I want to pull out the URL of the photo so I can put it inside the src attribute of the img tag. The paragraph under the heading is just trying to pull the values out - it won't be there in the finished code. The user enters in the information to the Macro window when they insert it to the page, and the MediaCurrent is used to choose a photo from the Media library. Please feel free to critique what I have there too, as I said I am a beginner at XSLT and have just looked at previous examples of code to produce this. Thanks, Rachel
|
|
Rank: Devotee
Joined: 12/11/2006 Posts: 47
|
Hi Rachel Try writing the following where you are trying to get the URL of the image. Code: <xsl:value-of select="umbraco.library:GetMedia(/macro/team_photo, false)/data [@alias = 'umbracoFile']"/>
I think this is going to do the trick for you.
/Jan
|
|
 Rank: Umbracoholic
Joined: 9/8/2006 Posts: 1,698 Location: KY, USA
|
Okay, let's assume that you can get the following string, as you mentioned at the top of your post... /media/278/lesley.jpg971465089jpg I assume that your macro uses a media picker associated with the "team_photo" property alias. Thus, when you create your $team_photo variable, you have the full media node. Here's the code I'd use to show the image (written right here in the forum editor so let me know if I mis-type anything :o) Code: <xsl:template match="/"> <xsl:variable name="team_name" select="/macro/team_name"/> <xsl:variable name="team_photo" select="/macro/team_photo"/>
<img> <xsl:attribute name="title"><xsl:value-of select="$team_name"/></xsl:attribute> <xsl:attribute name="alt"> Photo of <xsl:value-of select="$team_name"/> </xsl:attribute> <xsl:attribute name="src"> <xsl:value-of select="$team_photo/data [@alias='umbracoFile']"/> </xsl:attribute> </img>
</xsl:template>
If your $team_photo only contains a node id, you can use <xsl:variable name="team_photo_id" select="/macro/team_photo"/> <xsl:variable name="team_photo" select="umbraco.library:GetMedia($team_photo_id, 0)"/> And then proceed as above. cheers, doug.
MVP 2007-2009 - Official Umbraco Trainer for North America - Percipient Studios
|
|
Rank: Newbie
Joined: 9/14/2006 Posts: 9
|
Hi Jan, thanks for your suggestion... unfortunately I get this error when I paste that in? Code:Error occured System.Xml.XPath.XPathException: Function 'umbraco.library:GetMedia()' has failed. ---> System.FormatException: String was not recognized as a valid Boolean. at System.Boolean.Parse(String value) at System.Xml.Xsl.XsltOld.XsltCompileContext.XsltFunctionImpl.ToBoolean(Object argument) at System.Xml.Xsl.XsltOld.XsltCompileContext.XsltFunctionImpl.ConvertToXPathType(Object val, XPathResultType xt, TypeCode typeCode) at System.Xml.Xsl.XsltOld.XsltCompileContext.FuncExtension.Invoke(XsltContext xsltContext, Object[] args, XPathNavigator docContext) at MS.Internal.Xml.XPath.FunctionQuery.Evaluate(XPathNodeIterator nodeIterator) --- End of inner exception stack trace --- at MS.Internal.Xml.XPath.FunctionQuery.Evaluate(XPathNodeIterator nodeIterator) at MS.Internal.Xml.XPath.BaseAxisQuery.Evaluate(XPathNodeIterator nodeIterator) at MS.Internal.Xml.XPath.BaseAxisQuery.Evaluate(XPathNodeIterator nodeIterator) at System.Xml.Xsl.XsltOld.Processor.ValueOf(ActionFrame context, Int32 key) at System.Xml.Xsl.XsltOld.ValueOfAction.Execute(Processor processor, ActionFrame frame) at System.Xml.Xsl.XsltOld.ActionFrame.Execute(Processor processor) at System.Xml.Xsl.XsltOld.Processor.Execute() at System.Xml.Xsl.XsltOld.Processor.Execute(TextWriter writer) at System.Xml.Xsl.XslTransform.Transform(XPathNavigator input, XsltArgumentList args, TextWriter output, XmlResolver resolver) at System.Xml.Xsl.XslTransform.Transform(IXPathNavigable input, XsltArgumentList args, TextWriter output, XmlResolver resolver) at umbraco.presentation.webservices.codeEditorSave.SaveXslt(String fileName, String fileContents, Boolean ignoreDebugging)
|
|
Rank: Newbie
Joined: 9/14/2006 Posts: 9
|
Hi Doug, Thanks so much for your time on this, I really appreciate it! Unfortunately when I use that code, the src is empty. Then when I use the second lot of variables, I get this error: Code:Error occured System.Xml.XPath.XPathException: Function 'umbraco.library:GetMedia()' has failed. ---> System.OverflowException: Value was either too large or too small for an Int32. at System.Convert.ToInt32(Double value) at System.Double.System.IConvertible.ToInt32(IFormatProvider provider) at System.Convert.ChangeType(Object value, TypeCode typeCode, IFormatProvider provider) at System.Xml.Xsl.XsltOld.XsltCompileContext.XsltFunctionImpl.ToNumeric(Object argument, TypeCode typeCode) at System.Xml.Xsl.XsltOld.XsltCompileContext.XsltFunctionImpl.ConvertToXPathType(Object val, XPathResultType xt, TypeCode typeCode) at System.Xml.Xsl.XsltOld.XsltCompileContext.FuncExtension.Invoke(XsltContext xsltContext, Object[] args, XPathNavigator docContext) at MS.Internal.Xml.XPath.FunctionQuery.Evaluate(XPathNodeIterator nodeIterator) --- End of inner exception stack trace --- at MS.Internal.Xml.XPath.FunctionQuery.Evaluate(XPathNodeIterator nodeIterator) at System.Xml.Xsl.XsltOld.Processor.RunQuery(ActionFrame context, Int32 key) at System.Xml.Xsl.XsltOld.VariableAction.Execute(Processor processor, ActionFrame frame) at System.Xml.Xsl.XsltOld.ActionFrame.Execute(Processor processor) at System.Xml.Xsl.XsltOld.Processor.Execute() at System.Xml.Xsl.XsltOld.Processor.Execute(TextWriter writer) at System.Xml.Xsl.XslTransform.Transform(XPathNavigator input, XsltArgumentList args, TextWriter output, XmlResolver resolver) at System.Xml.Xsl.XslTransform.Transform(IXPathNavigable input, XsltArgumentList args, TextWriter output, XmlResolver resolver) at umbraco.presentation.webservices.codeEditorSave.SaveXslt(String fileName, String fileContents, Boolean ignoreDebugging)
:hmm: Any ideas of what I can do now?? Thanks, Rachel
|
|
Rank: Newbie
Joined: 9/14/2006 Posts: 9
|
Is anyone able to give me some insight to these errors and perhaps suggest a solution??
Thanks, Rachel
|
|
Rank: Newbie
Joined: 9/14/2006 Posts: 9
|
I have my images coming up correctly now! We changed the variable to read: Code: <xsl:variable name="team_photo_url" select="/macro/team_photo/node/data[@alias='umbracoFile']"/>
and the html bit to read: Code: <img src="{$team_photo_url}" alt="Photo of {$team_name}" title="{$team_name}" />
And it works! A nice clean solution I think :-)
|
|
|
Guest |