Jump to content
Claris Engage 2025 - March 25-26 Austin Texas ×

This topic is 7226 days old. Please don't post here. Open a new topic instead.

Recommended Posts

Posted

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

Posted

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>

Posted

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

Posted

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

Posted

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

Posted

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>

Posted

<?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>

Posted

Hi Fenton,

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

Greetings,

Kip

Posted

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

This topic is 7226 days old. Please don't post here. Open a new topic instead.

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
×
×
  • Create New...

Important Information

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