On 19 May 2009, at 19:05, Sam Fuqua wrote:

Hi Sam

I know that this isn't within the bounds of the w3 standard, but I was wondering if FOP has any way of handling JSON.
For example, if I have:
<root>
<element>
{"menu":{"key":"value","id":"idnum"}}
</element>
</root>
, is there any way to xpath into the JSON in the text node? I've seen it used in another xml parser, but wasn't sure if it's possible to reference element/menu/id in my XSL when I'm creating an FO document.

Not possible with FOP, I'm afraid, since JSON is Javascript, and unrelated to XML. To a general XML parser, the content of the element node is simply a text node. FOP has no embedded script engine to parse and evaluate it as a Javascript object.

The only way to get the value of the 'id' attribute of the object in standard XML/XSLT would thus be using something like:
 substring-before(substring-after(/root/element,'"id":"'),'"}')

Another route would be to translate the JSON object to XML, parse it as such, and then use normal XPath to get the requested attribute from something like:

<root><element><menu key="value" id="idnum" /></element></root>
or
<root><element><menu><key>value</key><id>idnum</id></menu></element></ root>

Regards

Andreas

---------------------------------------------------------------------
To unsubscribe, e-mail: fop-users-unsubscr...@xmlgraphics.apache.org
For additional commands, e-mail: fop-users-h...@xmlgraphics.apache.org

Reply via email to