Copied to clipboard

Flag this post as spam?

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


  • Jakob 38 posts 54 karma points
    Jul 13, 2010 @ 10:52
    Jakob
    0

    How to have a template have an xml header

    Hey. I'm trying to return an xml list from a template, but I can't get the header printed no matter what, it's like some filter in Umbraco is erasing it. 

    I've tried printing in python and xslt and simply writing it in the template, but no matter what this line:

    <?xml version="1.0" encoding="utf-8" ?>

    gets erased and simply displays blank. 

    What can I do about that?

  • Ismail Mayat 4511 posts 10091 karma points MVP 2x admin c-trib
    Jul 13, 2010 @ 10:56
    Ismail Mayat
    0

    Jakob,

    One way is to create an xml macro and in the xslt macro put the following

    <xsl:value-of select="umbraco.library:ChangeContentType('text/xml')"/>

     

    Regards

    Ismail

  • Jakob 38 posts 54 karma points
    Jul 13, 2010 @ 11:06
    Jakob
    0

    Thanks for your post Ismail. I Know this is not an xslt thread, but if you have a quick answer to why this doesn't work, I'd be very happy.

     

    <xsl:template match="/">

    <xsl:value-of select="umbraco.library:ChangeContentType('text/xml')"/>

    <playlist>

    <xsl:for-each select="$currentPage/node">

    <audiofile url="http://www.larica.dk{./data[@alias='AudioFile']}" title="{./data[@alias='Title']}" artist="{./data[@alias='Artist']}" />

    </xsl:for-each>

    </playlist>

    </xsl:template>

     

    returns 

    <playlist><audiofile url="/media/2976/nemo ft. joel, hr - næver til lunden.mp3title="næver til lunden" artist="nemo ft. joel" /></playlist>

    without the header

     

  • Ismail Mayat 4511 posts 10091 karma points MVP 2x admin c-trib
    Jul 13, 2010 @ 11:10
    Ismail Mayat
    0

    Jakob,

    The field audiofile is that type media current or file upload?  It looks like media current so what you need to do is

    {umbraco.library:GetMedia(./data[@alias='AudioFile'],false())/data[@alias='umbracoFile']}
  • Jakob 38 posts 54 karma points
    Jul 13, 2010 @ 11:12
    Jakob
    0

    I know that traditionally maybe it should be media, but it's actually an upload field. The playlist gets printed ok, it's just the header is missing (and I need the header for it to be interpreted correctly by a player).

  • Peter Duncanson 430 posts 1360 karma points c-trib
    Jul 13, 2010 @ 12:21
    Peter Duncanson
    0

    Make sure you don't have "omit-xml-declaration" set to yes in the top of one of your running XSL files/macros?

    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      version="1.0">
      <xsl:output method="xml" omit-xml-declaration="yes"/>

    Just delete the property if it is there.

     

    Additionally you are just rendering out text when you run a XSLT file so there should be nothing wrong with you writing it out into the file. Changing the content type will just change how the various agents (aka browsers in this case) that consume the "string" of xml process it.

    You might need to do some tricks to get it to render out though:

    <![CDATA[<?xml version="1.0" encoding="utf-8" ?>]]>

    That will stop it being processed by the XML/XSL processor as it will treat it just as text. As a result it will spit out your complete "string" of xml which an agent can then consume as XML.

    Hope that helps.

  • Jakob 38 posts 54 karma points
    Jul 13, 2010 @ 14:19
    Jakob
    0

    if i CDATA the tag it escapes the < charachters displaying it in the text, removing the omit-xml-declaration attribute doesn't seem to do anything. As mentioned I suspect that the xml header gets removed, since I can't simply write it in the template either, so I may be looking for a way to bypass this.

  • Peter Duncanson 430 posts 1360 karma points c-trib
    Jul 13, 2010 @ 14:40
    Peter Duncanson
    0

    What about this?

    <xsl:text disable-output-escaping="yes">&lt;?xml version="1.0" encoding="utf-8" ?&gt;</xsl:text>

    What you are wanting to do should be easy to achieve. Might need more info to dig into it anymore. Like you say could be a hardcoded check in Umbraco to prevent XML declarations being output but that seems a bit of a hacky way of doing it and not very Umbraco. Could easily be something else getting in the way.

Please Sign in or register to post replies

Write your reply to:

Draft