It should be possible. Did you concat() the strings (property name and index) and eventually encapsulate the result in a string()-function?
I believe you need the 'MediaCurrent' - property type instead of PropertyTypePicker. How many sidebarImage fields is the maximum? if your intention is to make a solution where the user can choose an indefinite number of sidebar-images, you're probably better off making a datatype for this purpose, but if you just have, say, 4 fields you could just hardcode the property names in your xslt
I don't have the code any more! I tried so many things that I / it got lost :-(
I managed to concat() "SidebarImage" and "1" (or what ever was passed in) but couldn't make use of it.
It isn't something for a user to do / use - it's built into the template / doc type. They have (currently) between 1 and 3 image / link pairs to use - it varies by doc type. In the template, I wanted to insert a macro call (the required number of times) which passed in the index value (1,2 or 3) and for it to produce the and HTML as appropriate (i.e no link if "SidebarLink" is empty) in the appropriate place.
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, Type conversionType, IFormatProvider provider)
at System.Xml.Xsl.Runtime.XmlQueryRuntime.ChangeTypeXsltArgument(XmlQueryType xmlType, Object value, Type destinationType)
at System.Xml.Xsl.Runtime.XmlQueryContext.InvokeXsltLateBoundFunction(String name, String namespaceUri, IList`1[] args)
at (XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}runtime, XPathNavigator {urn:schemas-microsoft-com:xslt-debug}current)
at Root(XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}runtime)
at Execute(XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}runtime)
at System.Xml.Xsl.XmlILCommand.Execute(Object defaultDocument, XmlResolver dataSources, XsltArgumentList argumentList, XmlSequenceWriter results)
at System.Xml.Xsl.XmlILCommand.Execute(Object defaultDocument, XmlResolver dataSources, XsltArgumentList argumentList, XmlWriter writer, Boolean closeWriter)
at System.Xml.Xsl.XmlILCommand.Execute(IXPathNavigable contextDocument, XmlResolver dataSources, XsltArgumentList argumentList, XmlWriter results)
at System.Xml.Xsl.XmlILCommand.Execute(IXPathNavigable contextDocument, XmlResolver dataSources, XsltArgumentList argumentList, TextWriter results)
at System.Xml.Xsl.XslCompiledTransform.Transform(IXPathNavigable input, XsltArgumentList arguments, TextWriter results)
at umbraco.presentation.webservices.codeEditorSave.SaveXslt(String fileName, String oldName, String fileContents, Boolean ignoreDebugging)[/code]
Error is what it says... Any time you're using variables or parameters, consider adding xsl:if constructs as those var/params have NO actual value until runtime and at saving time, the xslt is checked against the topnode which may or may not exist on that top level node!
Using dynamically created page variable names
I have a document type that has property pairs called "SidebarImage1" / "SidebarLink1", "SidebarImage2" / "SidebarLink2", etc.
If there is a "SidebarLink" value then I want to put a link around the image ( tag) otherwise I just want to display the image. "SidebarImage" is a Media Picker and "SidebarLink" is a Content Picker.
As there are a number of these images on a page (doc type), I thought I'd create a XSLT / macro that passes in an index value ... i.e. 1, 2, 3, etc, with the intention of appending the index to the property name ("SidebarImage" + "1" = "SidebarImage1"). Then I could use that to obtain the ID of the image from the current document.
Well, it sounded like a good idea when I started!
I have managed to join the two bits together, but I can't then make use of it to obtain the image ID!?
I also tried changing the macro parameter to a propertyTypePicker, but I couldn't get that to work either! :-(
Does the above make sense? Is what I'm trying to do possible? Any sample code would be most welcome.
It should be possible. Did you concat() the strings (property name and index) and eventually encapsulate the result in a string()-function?
I believe you need the 'MediaCurrent' - property type instead of PropertyTypePicker. How many sidebarImage fields is the maximum? if your intention is to make a solution where the user can choose an indefinite number of sidebar-images, you're probably better off making a datatype for this purpose, but if you just have, say, 4 fields you could just hardcode the property names in your xslt
I don't have the code any more! I tried so many things that I / it got lost :-(
I managed to concat() "SidebarImage" and "1" (or what ever was passed in) but couldn't make use of it.
It isn't something for a user to do / use - it's built into the template / doc type. They have (currently) between 1 and 3 image / link pairs to use - it varies by doc type. In the template, I wanted to insert a macro call (the required number of times) which passed in the index value (1,2 or 3) and for it to produce the and HTML as appropriate (i.e no link if "SidebarLink" is empty) in the appropriate place.
Basically, I think I need to know how to concatenate "SidebarImage" and "1" to get "SidebarImage1" and to then be able to access the page property of that name, which will give me the ID of a media library image. Then I "just" need to get the path to the image and create a tag!
OK, I have the following XSLT which works, but I have to select "Ignore errors" when saving?!
Have I got something wrong, or is there something missing?
[code]
]>
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">
[/code]
This is the error I get -
[code]Error occured
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, Type conversionType, IFormatProvider provider)
at System.Xml.Xsl.Runtime.XmlQueryRuntime.ChangeTypeXsltArgument(XmlQueryType xmlType, Object value, Type destinationType)
at System.Xml.Xsl.Runtime.XmlQueryContext.InvokeXsltLateBoundFunction(String name, String namespaceUri, IList`1[] args)
at (XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}runtime, XPathNavigator {urn:schemas-microsoft-com:xslt-debug}current)
at Root(XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}runtime)
at Execute(XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}runtime)
at System.Xml.Xsl.XmlILCommand.Execute(Object defaultDocument, XmlResolver dataSources, XsltArgumentList argumentList, XmlSequenceWriter results)
at System.Xml.Xsl.XmlILCommand.Execute(Object defaultDocument, XmlResolver dataSources, XsltArgumentList argumentList, XmlWriter writer, Boolean closeWriter)
at System.Xml.Xsl.XmlILCommand.Execute(IXPathNavigable contextDocument, XmlResolver dataSources, XsltArgumentList argumentList, XmlWriter results)
at System.Xml.Xsl.XmlILCommand.Execute(IXPathNavigable contextDocument, XmlResolver dataSources, XsltArgumentList argumentList, TextWriter results)
at System.Xml.Xsl.XslCompiledTransform.Transform(IXPathNavigable input, XsltArgumentList arguments, TextWriter results)
at umbraco.presentation.webservices.codeEditorSave.SaveXslt(String fileName, String oldName, String fileContents, Boolean ignoreDebugging)[/code]
Hi Gordon,
Error is what it says... Any time you're using variables or parameters, consider adding xsl:if constructs as those var/params have NO actual value until runtime and at saving time, the xslt is checked against the topnode which may or may not exist on that top level node!
Hope this helps.
Regards,
/Dirk
[quote=Dirk]Hope this helps.[/quote]
Yes, it did thank you :-)
I added an xsl:if around the img tag bit and it now saves without error.
is working on a reply...