2013-05-02- Risten2 Meeting
Risten2 meeting
- since last meeting
- next
Since last meeting
- rewrite search to avoid overwrite issue - DONE
- rewrite article fetching to add json attributes (no other changes to the article xml)
Problems with the last one:
<article dict="{root($hit)/r/@id}" name="{$dictName}"> <term>{string($hit)}</term> { for $entry in $hit/.. return ( <e>{string($entry)} <lg><l>{$entry//l}</l></lg> <mg>{string($entry/mg) for $tg in $entry//tg return ( <tg json:array="true"> {$tg} </tg> } </mg> </e> ) } </article>
Instead of using XQuery to transform the xml, use xsl:
transform:transform($entry, xs:anyURI("add-json-array.xsl"), ())
with the stylesheet add-json-array.xsl containing the following:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:json="http://json.org/" > <xsl:template match="mg|tg|t"> <xsl:element name="{name()}" <xsl:attribute name="json:array" value="true"/> <xsl:copy> <xsl:apply-templates select="@*|node()"/> </xsl:copy> </xsl:element> </xsl:template> <xsl:template match="@*|node()"> <xsl:copy> <xsl:apply-templates select="@*|node()"/> </xsl:copy> </xsl:template> </xsl:stylesheet>
The resulting XQuery:
<article dict="{root($hit)/r/@id}" name="{$dictName}"> <term>{string($hit)}</term> { for $entry in $hit/.. return transform:transform($entry, xs:anyURI("add-json-array.xsl"), ()) } </article>
returns the complete xml as json in a consistent structure, althogh the json array nodes are duplicated. Probably not a major issue, though, as long as it is consistent.