February 4, 200521 yr 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
February 4, 200521 yr 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 "<" and "/>", since "<" can't stand alone in an XML file. Then it must stop them from being escaped; or else the result ends up with "<" 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"><</xsl:text> <xsl:value-of select="name()"/> <xsl:text disable-output-escaping="yes">></xsl:text> <xsl:value-of select="."/> <xsl:text disable-output-escaping="yes"></</xsl:text> <xsl:value-of select="name()"/> <xsl:text disable-output-escaping="yes">></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>
February 7, 200521 yr Author Thank you very much Fenton. Also for the w3 link! I certainly can use this information in building the stylesheets!
February 7, 200521 yr 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
February 7, 200521 yr 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
February 7, 200521 yr 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> </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"><</xsl:text> <xsl:value-of select="name()"/> <xsl:text disable-output-escaping="yes">></xsl:text> <xsl:value-of select="."/> <xsl:text disable-output-escaping="yes"></</xsl:text> <xsl:value-of select="name()"/> <xsl:text disable-output-escaping="yes">></xsl:text> </xsl:otherwise> </xsl:choose> </xsl:for-each> </xsl:for-each> </xsl:template> </xsl:stylesheet>
February 7, 200521 yr <?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> </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"><</xsl:text> <xsl:value-of select="../../../../fmp:METADATA/fmp:FIELD[$theCount]/@NAME"/> <xsl:text disable-output-escaping="yes">></xsl:text> <xsl:value-of select="." /> <xsl:text disable-output-escaping="yes"></</xsl:text> <xsl:value-of select="../../../../fmp:METADATA/fmp:FIELD[$theCount]/@NAME"/> <xsl:text disable-output-escaping="yes">></xsl:text> </xsl:otherwise> </xsl:choose> </xsl:for-each> </xsl:template> </xsl:stylesheet>
February 8, 200521 yr Author Hi Fenton, Something seems to be wrong in the fmp xmlresult. I get an error in line 7 position 2. Greetings, Kip
February 11, 200521 yr 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
Create an account or sign in to comment