xslt json output
This is an open discussion with 46 replies, filed under XSLT.
Search
I think I will add them to mine if you don’t mind.
Of course not, add away! Much simpler that way.
I only have one concearn: I want to be able to address elements with attributes the same way as ones without attributes.
For now, the ones with attributes have a field “value”, the other ones don’t, right?
That’s right, yeah. Not sure there’s a particularly neat way around that.
I stumbled across this XSLTJSON utility today, it gets around the problem of what to do with attributes by appending @
to the start of those objects. Thought it might be of interest to those who want some dead simple JSON action.
@makenosound
Nice! thanks. Just for posterity, be sure to get the ‘lite’ version from the Makenosound’s link if you want to use it in Symphony (XSLT 1 version).
where’s this file:
<xsl:import href=”../../utilities/generic/string-replace.xsl” />
i don’t see it in the default 2.0.8 rc3 build
It’s a XSLT utility from the downloads section.
ah, thanks klaftertief
I stumbled across this XSLTJSON utility today,
I can’t open that page. Can anyone post it here?
Here is a cached version and i found this utility helpful as well.
Cheers Jonas!
i was having some issues with arrays being created (ie. multiple <entry> modes) so i modified @makenosound’s latest gist (didn’t fork it) - xml2json. not too much was really changed, just added some variables and to use in place of some xpath. The biggest change was selecting just [1]
st previous or next sibling in the xml. haven’t done any extensive testing, though.
does anyone know how to strip the line breaks from a node with formatted html output? i already have <xsl:strip-space elements="* | @*" />
in the template, but that doesn’t seem to do anything to nodes with html in it (using tinymce editor):
<bio mode="formatted"><p>This is plain only now. <strong>This is bold. <em>This is bold and italic. <span style="text-decoration: underline;">This is bold, italic, and underlined.</span><span style="font-style: normal; font-weight: normal;"> This text is back to normal.</span></em></strong></p> <p></p> <ul> <li>I have one unordered list item</li> <li>A second item</li> <li>And finally a third item</li> </ul> <div><ol> <li>This is an ordered list: 1</li> <li>this is an ordered list: 2</li> <li>And this is 3</li> </ol> <div>Need to remove all these line breaks on the output</div> </div> <p></p></bio>
i added the 'json' => 'application/json'
mapping to the config.php
file, but i’m still seeing this as my content type header:
Content-Type text/html; charset=utf-8
I added json
as the Page Type
, but that didn’t seem to do anything for me. What am i missing still?
I’m sure that should be 'json' => 'application/x-javascript'
, I’ve never heard of the application/json
mime type, and it is JavaScript after all…
I guess you’ve got the Content Type Mappings extension enabled then?
ya i have the Content Type Mappings extensions installed. I’m looking to only return json snippets and have been seeing application/json
as the mime type for that. A quick google search points me to a stack overflow post to confirm this.
Well you learn something new every day! Thanks for pointing that out.
Hello
I have problem with receive json from my page. Could someone show a jquery script? My script does not cause errors and no gives the results.
In the console, the request is displayed twice, once with a 200 OK status and type of application / json, a second time with a status 301 Moved Permanently and type text / html.
Create an account or sign in to comment.
@phoque: I’m happy with where my version of this is at now—it’s working as it should in my current project. Do you want to roll the alterations into your utility or shall I add it separately?