Skip to content
View in the app

A better way to browse. Learn more.

FMForums.com

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Exporting to XML with stylesheet

Featured Replies

I am really new to this so I hope someone can get me on the way.

Several clients ask me to provide a XML using their naming convention.

For instance I have a field: "clients", which name in the export to the XML should be substituted by "customers".

My guess is that the easiest way would be by using a stylesheet to change the names automatically rather than using a XML editor each time an export is made.

However I don

XML guru? Not quite. I just stand there wondering what's up while everyone else takes a quick step back :-]

Yes, this can be done. But I'm a little confused. Since you don't know XSL, how are you managing to give customers an XML file that they can use? Export DSORESULT?

Also, the obvious question; why don't you just change the name of the field?

The following will more or less recreate the DSO XML Export, but adds a test that the field name does not equal "client"; in which case it uses <customer>; otherwise it rebuilds the <field name></field name> tags.

It must build the "<" and "/>" from "&lt;" and "/&gt;", since "<" can't stand alone in an XML file. Then it must stop them from being escaped; or else the result ends up with "&lt;" instead of "<". Something like that. Also useful to get full URL tags out of FileMaker into HTML without getting mangled.

You can do similar for an XMLRESULT Export, but it would be a bit more complex. Or, you can just hard-code all the field names, using "for-each" for each. That would be tedious, but simpler. I'm not much into tedious.

<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fmp="http://www.filemaker.com/fmpdsoresult" exclude-result-prefixes="fmp">

<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>

<xsl:template match="/">

<xsl:for-each select="fmp:FMPDSORESULT/fmp:ROW">

<xsl:for-each select="./*">

<xsl:choose>

<xsl:when test="name()!='client'">

<xsl:text disable-output-escaping="yes">&lt;</xsl:text>

<xsl:value-of select="name()"/>

<xsl:text disable-output-escaping="yes">&gt;</xsl:text>

<xsl:value-of select="."/>

<xsl:text disable-output-escaping="yes">&lt;/</xsl:text>

<xsl:value-of select="name()"/>

<xsl:text disable-output-escaping="yes">&gt;</xsl:text>

</xsl:when>

<xsl:otherwise>

<customer>

<xsl:value-of select="."/>

</customer>

</xsl:otherwise>

</xsl:choose>

</xsl:for-each>

</xsl:for-each>

</xsl:template>

</xsl:stylesheet>

  • Author

Thank you very much Fenton. Also for the w3 link! I certainly can use this information in building the stylesheets!

  • Author

Hi Fenton.

I have another question concerning this subject.

Replacing the field info now works fine when using the DSO export. What change would I have to make to use the XSL for the XMLresult export?

Greetings

Kip

  • Author

omg One final question.

What would the script look like if I want to change two fieldnames? for instance clients into "customer" and clientid into "ID"

Thank you in advance,

Kip

DSO:

<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fmp="http://www.filemaker.com/fmpdsoresult" exclude-result-prefixes="fmp">

<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>

<xsl:template match="/">

<xsl:for-each select="fmp:FMPDSORESULT/fmp:ROW">

<xsl:for-each select="./*">

<xsl:text>&#10;</xsl:text>

<xsl:choose>

<xsl:when test="name()='clientid'">

<ID>

<xsl:value-of select="."/>

</ID>

</xsl:when>

<xsl:when test="name()='client'">

<customer>

<xsl:value-of select="."/>

</customer>

</xsl:when>

<xsl:otherwise>

<xsl:text disable-output-escaping="yes">&lt;</xsl:text>

<xsl:value-of select="name()"/>

<xsl:text disable-output-escaping="yes">&gt;</xsl:text>

<xsl:value-of select="."/>

<xsl:text disable-output-escaping="yes">&lt;/</xsl:text>

<xsl:value-of select="name()"/>

<xsl:text disable-output-escaping="yes">&gt;</xsl:text>

</xsl:otherwise>

</xsl:choose>

</xsl:for-each>

</xsl:for-each>

</xsl:template>

</xsl:stylesheet>

<?xml version='1.0' encoding='utf-8'?>

<xsl:stylesheet xmlns:fmp="http://www.filemaker.com/fmpxmlresult"

exclude-result-prefixes="fmp" version="1.0"

xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output method="xml"/>

<xsl:template match="/">

<xsl:for-each select="fmp:FMPXMLRESULT/fmp:RESULTSET/fmp:ROW/fmp:COL/fmp:DATA">

<xsl:variable name="theCount" select="position()"></xsl:variable>

<!-- this count variable lets us go back up and get the correct field name from the Metadata block -->

<xsl:text>&#10;</xsl:text>

<xsl:choose>

<xsl:when test="../../../../fmp:METADATA/fmp:FIELD[$theCount]/@NAME='clientid'">

<ID>

<xsl:value-of select="." />

</ID>

</xsl:when>

<xsl:when test="../../../../fmp:METADATA/fmp:FIELD[$theCount]/@NAME='client'">

<customer>

<xsl:value-of select="." />

</customer>

</xsl:when>

<xsl:otherwise>

<xsl:text disable-output-escaping="yes">&lt;</xsl:text>

<xsl:value-of select="../../../../fmp:METADATA/fmp:FIELD[$theCount]/@NAME"/>

<xsl:text disable-output-escaping="yes">&gt;</xsl:text>

<xsl:value-of select="." />

<xsl:text disable-output-escaping="yes">&lt;/</xsl:text>

<xsl:value-of select="../../../../fmp:METADATA/fmp:FIELD[$theCount]/@NAME"/>

<xsl:text disable-output-escaping="yes">&gt;</xsl:text>

</xsl:otherwise>

</xsl:choose>

</xsl:for-each>

</xsl:template>

</xsl:stylesheet>

  • Author

Hi Fenton,

Something seems to be wrong in the fmp xmlresult. I get an error in line 7 position 2.

Greetings,

Kip

  • Author

Never mind, I completeley solved it! Thanks for getting me started. I managed to provide each customer a fitting xml now generated through xsl.

Greetings,

Kip laugh.gif

Create an account or sign in to comment

Important Information

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

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.