Jump to content
Sign in to follow this  
AlanTrewartha

[Solutions] fmresultsetjson.xsl

Recommended Posts

fmresultsetjson.xsl


XSLT to convert Filemaker's REST web-service XML response into clean JSON

https://twitter.com/alantrewartha

2017-03-06

Adapted from the original Six Fried Rice XSLT here http://sixfriedrice.com/wp/products/filemaker-to-json-converter/

Changed:
* single quotes to JSON-standard double-quotes
* removed "fieldDefinitions" block (personal preference)
* stopped every field value being presented as an [ array ] even when not a "repeating field"
* added whitespace escaping code

The white-space escaping code was entirely cribbed from
https://github.com/doekman/xml2json-xslt/blob/master/xml2json.xsl


 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Similar Content

    • By eyepro
      I'm very very very newbie on xml.
      What I need to understand is if it's possibile export in this way.
      I use a xsl stylesheet to export from FM.
       
      I was able to use the <xsl:for-each to export details in the way I want:
      <xsl:for-each select="fmp:FMPXMLRESULT/fmp:RESULTSET/fmp:ROW">
              <Details>
                  <Code><xsl:value-of select="fmp:COL[2]/fmp:DATA"/></Code>
                  <WTN><xsl:value-of select="fmp:COL[3]/fmp:DATA"/></WTN>
                  <Date><xsl:value-of select="fmp:COL[4]/fmp:DATA"/></Date>
                  
      result:
      <Details>
      <Code>0280c1</Code>
      <WTN>1</WTN>
      <Date>10/04/2018</Date>
      </Details>
      <Details>
      <Code>0280c2</Code>
      <WTN>2</WTN>
      <Date>10/04/2018</Date>
      </Details>
      <Details>
      <Code>0280c3</Code>
      <WTN>3</WTN>
      <Date>10/04/2018</Date>
      </Details>
      what i need to know is how put the fmp:COL[1] above the <xsl:for-each to get this:
      <CUSTOMER>ABC</CUSTOMER>
      <INVOICE>01</INVOICE>
      <Details>
      <PrimaryKey>0280c1</PrimaryKey>
      <WTN>1</WTN>
      <Date>10/04/2018</Date>
      <Colours/>
      </Details>
      <Details>
      <PrimaryKey>0280c2</PrimaryKey>
      <WTN>2</WTN>
      <Date>10/04/2018</Date>
      <Colours/>
      </Details>
      <Details>
      <PrimaryKey>0280c3</PrimaryKey>
      <WTN>3</WTN>
      <Date>10/04/2018</Date>
      <Colours/>
      </Details>
       
      Thanks in advance.
    • By Matt Navarre
      Announcing fmSearchResults 5. This latest download delivers new features with simple implementation. And it's free!
      fmSearchResults 5 adds fast, multi-table searching to your FileMaker solutions by importing a few scripts and pasting a simple search field on to your layouts. It feels like the type of Google search that all your users are already familiar with, and it’s far more powerful than FileMaker’s Quickfind feature, because it searches across multiple tables and has data-type awareness.
      Read more about the new features and download it now!
      Implementation is so simple, watch me do it 5 minutes (and 12 seconds).
    • By Brent Durland
      If you love FileMaker but are new to JSON, download this free educational tool and start learning!
      http://www.filemakerforever.com/articles/134
       

    • By DarioDN
      Dear all, I've just create a script to export my records in multiple xml file (one xml for each record) applying also an XSL stylesheet.
      So, if I use the style.xsl taking from my computer ("source" button when filemaker ask me to select the file) it works. If I put the same file online, it doesn't work giving me a SAXParseException error: internal error in NetAccess (occurred in an unknown entity, at line 0, column 0).
      In the same folder where I have the style.xsl there are other xsl files that works, but they are used to "import" process (from XML to FILEMAKER, while in this case I'm working to an export process, from FILEMAKER to XML, I don't know if this could be the problem)
      Someone could help me to understand the error? Thank you
      <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fmp="http://www.filemaker.com/fmpxmlresult" exclude-result-prefixes="fmp" > <xsl:output omit-xml-declaration="yes" indent="yes"/> <xsl:strip-space elements="*"/> <xsl:template match="fmp:FMPXMLRESULT"> <xsl:for-each select="fmp:RESULTSET/fmp:ROW"> <xsl:text>&#xA;</xsl:text> <xsl:text disable-output-escaping="yes">&lt;!--</xsl:text> <xsl:value-of select="fmp:COL[1]/fmp:DATA"/>.<xsl:value-of select="fmp:COL[2]/fmp:DATA"/>.<xsl:value-of select="fmp:COL[3]/fmp:DATA"/><xsl:text disable-output-escaping="yes">--&gt;</xsl:text> <problem display_name="Checkboxes" > <choiceresponse> <label><xsl:value-of select="fmp:COL[4]/fmp:DATA"/></label> <checkboxgroup> <choice correct="{fmp:COL[6]/fmp:DATA}"> <xsl:value-of select="fmp:COL[5]/fmp:DATA"/> <choicehint selected="true"><xsl:value-of select="fmp:COL[7]/fmp:DATA"/> </choicehint> </choice> <choice correct="{fmp:COL[9]/fmp:DATA}"> <xsl:value-of select="fmp:COL[8]/fmp:DATA"/> <choicehint selected="true"><xsl:value-of select="fmp:COL[10]/fmp:DATA"/></choicehint> </choice> <choice correct="{fmp:COL[12]/fmp:DATA}"> <xsl:value-of select="fmp:COL[11]/fmp:DATA"/> <choicehint selected="true"><xsl:value-of select="fmp:COL[13]/fmp:DATA"/></choicehint> </choice> </checkboxgroup> </choiceresponse> </problem> <xsl:text>&#xA;</xsl:text> </xsl:for-each> </xsl:template> </xsl:stylesheet>  
    • By jayivan
      I am working on an API integration from FileMaker 17 to Emma. Generally when I work on a new API, I get the curl working on the command line and then translate that into FM. But I've hit a roadblock with one particular API call while my other API calls to Emma are successful. (In the example below, I substituted out sensitive data with all caps.)
      From the command line, the code is:
      curl -u USER:PASS -H "Accept:application/json" -H "Content-type: application/json" -X POST -d '{"fields": {"name_first": "TESTFIRST","name_last": "TESTLAST","eligible": "false","expiration": "@D:2019-06-30"},"group_ids": ["GROUPIDNUMBER"],"email": "EMAIL@EMAIL.COM","opt_in_confirmation": "false"}' "https://api.e2ma.net/ACCOUNTNUMBER/members/signup"
      This command is successful.  The server responds with the individuals' emma id and group confirmation. 
      This fails using Insert from URL within FM though. While eventually I'll use FileMaker fields for an individual record's names, email, and expiration dates, I did not use fields in my testing in order to duplicate the command line exactly. In Insert from URL:
      The URL is "https://api.e2ma.net/ACCOUNTNUMBER/members/signup"
      The curl option is "-u USER:PASS -H \"Accept:application/json\" -H \"Content-type: application/json\" -X POST -d '{\"fields\": {\"name_first\": \"TESTFIRST\",\"name_last\": \"TESTLAST\",\"eligible\": \"false\",\"expiration\": \"@D:2101-06-30\"},\"group_ids\": [\"GROUPIDNUMBER\"],\"email\": \"EMAIL@EMAIL.COM\",\"opt_in_confirmation\": \"false\"}'"
       
      Can anyone identify the problem or suggest a workaround? My experience with API integration with FM is limited, but anything I could get working via the command line, I've been able to get working within FM until this.
  • Who Viewed the Topic

    2 members have viewed this topic:
    reynir  DavidTO 
×

Important Information

By using this site, you agree to our Terms of Use.