1 / 14

PCF DATA OUTPUTS

PCF DATA OUTPUTS. AKIFUMI YAMAMOTO | OMNIUPDATE. Requirements for this Workshop. LET’S MAKE SURE YOU’RE IN THE RIGHT PLACE. Knowledge of basic programming concepts Conditionals (if else), loops (for, foreach), and functions Knowledge of XML and JSON data formats Familiar with XSLT syntax

vian
Download Presentation

PCF DATA OUTPUTS

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. PCF DATA OUTPUTS AKIFUMI YAMAMOTO|OMNIUPDATE

  2. Requirements for this Workshop • LET’S MAKE SURE YOU’RE IN THE RIGHT PLACE • Knowledge of basic programming concepts • Conditionals (if else), loops (for, foreach), and functions • Knowledge of XML and JSON data formats • Familiar with XSLT syntax • Basic understanding of XSLT Elements • Basic understanding of XPath axes and expressions • Basic understanding of XPath functions

  3. Workshop Overview • OU Campus and XSLT • Conditionals (if else), loops (for, foreach), and functions • XSLT for data outputs • JSON output methods • fn:xml-to-json() • fn:serialize() • <xsl:map>data object

  4. OU Campus and XSLT • OU Campus uses XSLT • Extensible Stylesheet Language Transformations • Great for transforming A (pcf) into B (anything) • A = OU Campus Templates • PCF – A form of content data in XML format • B = Any output we want • Usually a web output (.html, .php, .aspx, etc) • We can do other outputs (.xml, .json, etc)

  5. Transforming A to B in OU Campus • <?pcf-stylesheet path="/path/to/xsl-file.xsl" title="Home Page" extension="html"?> • The pcf-stylesheet processing instruction determines the stylesheet and the output extension. • Filename cannot be altered. • Multiple outputs can be achieved with multiple pcf-stylesheet declarations. • Visit the Support Site for more information

  6. Using XSLT to Output Data • XML AND JSON • XML Output • Fairly straightforward • XML is similar to HTML, so not much needs to change from web output • JSON Output • A little more work • Essentially an XML to JSON conversion • We will explore this transformation

  7. JSON Output • Use fn:xml-to-json() • Must build an XML data with a specific structure • https://www.w3.org/TR/xpath-functions-31/#json-to-xml-mapping • A bug in 9.7.0.2 for empty objects/arrays: https://saxonica.plan.io/issues/2692 • Use fn:serialize() • fn:xml-to-json()isn’t perfect; has bugs in version 9.7.0.2 • Must construct a map object in XSL • http://www.saxonica.com/documentation/#!functions/fn/serialize

  8. JSON Output Original Data Build Map Convert fn:mapXML Tree xml-to-json() Original Data xsl:mapData Object serialize()

  9. Desired JSON { "updated":"2014-02-04T18:50:45", "uptodate":true, "author":null, "arrayObject": { "arrayOne": [ 299, 322 ],…

  10. fn:xml-to-json() Format • OPTION 1 <map xmlns="http://www.w3.org/2005/xpath-functions"> <string key="updated">2014-02-04T18:50:45</string> <booleankey="uptodate">true</boolean> <null key="author"/> <map key="arrayObject"> <array key="arrayOne"> <number>299</number> <number>322</number> </array>

  11. fn:xml-to-json() Walk Through • Understand the PCF • Add secondary output • Implement in XSLT • Mapping reference: https://www.w3.org/TR/xpath-functions-31/#json-to-xml-mapping • xsl:outputreference: http://www.saxonica.com/documentation/#!xsl-elements/output • xsl:modereference: http://www.saxonica.com/documentation/#!xsl-elements/mode • fn:serializereference: http://www.saxonica.com/documentation/#!functions/fn/serialize

  12. fn:serialize() Format • OPTION 2 <xsl:map> <xsl:map-entrykey="'updated'" select="'2014-02-04T18:50:45'"/> <xsl:map-entrykey="'uptodate'" select="true()"/> <xsl:map-entrykey="'author'"/> <xsl:map-entrykey="'arrayObject'"> <xsl:map> <xsl:map-entrykey="'arrayOne'" select="array{(299, 322)}"/>

  13. <xsl:map> and fn:serialize() Demo • Create an XSL map object using the <xsl:map>construct • http://www.saxonica.com/documentation/#!xsl-elements/map • Utilize the new array data type for arrays • http://www.saxonica.com/documentation/#!expressions/xpath31arrays • Specify the method in the second argument of fn:serialize(): • map{ • 'method': 'json', • 'json-node-output-method': 'html', • 'indent': true() • }

  14. THANK YOU! PLEASE SHARE YOUR FEEDBACK: WWW.SLIDO.COM #OUTC19

More Related