Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Mikael Mørup 297 posts 326 karma points
    Jan 07, 2009 @ 16:39
    Mikael Mørup
    0

    XSLT macro parameter problem

    I'm trying to create a macro with a parameter. The macro should allow me to select a picture from the media lib.

    I added a parameter to the macro, i would like it to be of the mediaPicker type, but that is not available, so i chose the currentMedia type.

    When i run the macro i can select a picture, and it says "updated with ID: 1098, which is the correct media id.

    But when i try to acces the parametervalue in my XSLT like this :



    I get this string : /media/1420/pic1.jpg80060028521jpg

    insted of the mediaId i was hoping for.

    How can i get my mediId from the macro instead?

    Thanks
    Mikael

  • Hal Lesesne 25 posts 25 karma points
    Jan 08, 2009 @ 16:28
    Hal Lesesne
    1

    I think that you actually want the @id attribute of the node /macro/picture/node, however I am getting an error when I try to select /macro/picture/node/@id - not sure why exactly, but the error I get when I switch to umbDebug is something like the following:

    An item of type 'Attribute' cannot be constructed within a node of type 'Root'.

    The full error is

    Error parsing XSLT test.xslt
    An item of type 'Attribute' cannot be constructed within a node of type 'Root'.
    at System.Xml.Xsl.Runtime.XmlQueryOutput.ThrowInvalidStateError(XPathNodeType constructorType)
    at System.Xml.Xsl.Runtime.XmlQueryOutput.ConstructInEnumAttrs(XPathNodeType rootType)
    at System.Xml.Xsl.Runtime.XmlQueryOutput.WriteStartAttribute(String prefix, String localName, String ns)
    at System.Xml.Xsl.Runtime.XmlQueryOutput.StartCopy(XPathNavigator navigator, Boolean callChk)
    at System.Xml.Xsl.Runtime.XmlQueryOutput.CopyNode(XPathNavigator navigator)
    at System.Xml.Xsl.Runtime.XmlQueryOutput.WriteItem(XPathItem item)
    at

  • Mikael Mørup 297 posts 326 karma points
    Jan 08, 2009 @ 18:20
    Mikael Mørup
    0

    Thanks

    I will give it a go when tomorrow.

    Mikael

  • Mikael Mørup 297 posts 326 karma points
    Jan 09, 2009 @ 12:38
    Mikael Mørup
    0

    I have now confirmed that your suggested solution also works for me.

    Thanks

  • Ruald Gerber 20 posts 41 karma points
    Jun 09, 2011 @ 13:28
    Ruald Gerber
    0

    Hi

    Have the syntax changed? I'm doing something similar and just cant get it to work. Im using Umbraco 4.7.

    Thanks

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Jun 09, 2011 @ 14:03
    Tom Fulton
    0

    Hi Ruald,

    Yes, the syntax has changed - the "node" should be replaced with the alias of your Media Type.  For example if your media type is an image:

    <xsl:value-of select="/macro/picture/Image/@id" />

    Or if you expect different media types you can use a wildcard:

    <xsl:value-of select="/macro/picture/*/@id" />

    Also to get the filename or any other property:

    <xsl:value-of select="/macro/picture/*/umbracoFile" />

    Hope this helps,
    Tom

  • Ruald Gerber 20 posts 41 karma points
    Jun 09, 2011 @ 15:19
    Ruald Gerber
    0

    Brilliant, that works!

    Thanks a lot.

Please Sign in or register to post replies

Write your reply to:

Draft