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:
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).
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:
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.
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.
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.
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?
Jakob,
One way is to create an xml macro and in the xslt macro put the following
Regards
Ismail
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.mp3" title="næver til lunden" artist="nemo ft. joel" /></playlist>
without the header
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']}
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).
Make sure you don't have "omit-xml-declaration" set to yes in the top of one of your running XSL files/macros?
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:
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.
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.
What about this?
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.
is working on a reply...