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

Simple XML Export but to include repetitions


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

Recommended Posts

Posted

Hi

Im after a bit of help please

I have a small test database that I'm trying to figure out if its at all possible to export a single xml file to give me a result like this:

<?xml version="1.0" encoding="UTF-8"?>
<JOB>
<PrimaryKey>88B2BDCE-A0B2-41EB-B190-0480DF3AD6A9</PrimaryKey>
<WTN>3453</WTN>
<Customer>Bosch</Customer>
<Colours1>Red</Colours1>
<Colours2>Blue</Colours2>
<Colours3>Yellow</Colours3>
<Colours4>Green</Colours4>
<Colours5>Pink</Colours5>
</JOB>
 

everything is working correctly apart from the Colours field that contains 5 repetitions. my test.xsl just gives me this result:

<?xml version="1.0" encoding="UTF-8"?>
<JOB>
<PrimaryKey>88B2BDCE-A0B2-41EB-B190-0480DF3AD6A9</PrimaryKey>
<WTN>3453</WTN>
<Customer>Bosch</Customer>
<Colours>Red</Colours>
</JOB>
 

<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 method="xml" version="1.0" encoding="UTF-8" indent="yes"/>

<xsl:template match="/">
    <JOB>
        <xsl:for-each select="fmp:FMPXMLRESULT/fmp:RESULTSET/fmp:ROW">
            <PrimaryKey><xsl:value-of select="fmp:COL[1]/fmp:DATA"/></PrimaryKey>
            <WTN><xsl:value-of select="fmp:COL[2]/fmp:DATA"/></WTN>
            <Customer><xsl:value-of select="fmp:COL[3]/fmp:DATA"/></Customer>
            <Colours><xsl:value-of select="fmp:COL[4]/fmp:DATA"/></Colours>
            </xsl:for-each>
        </JOB>
    </xsl:template>
</xsl:stylesheet>        
 

I know I can just create 5 separate colour fields and export them individually but this is just a test database for a much bigger database that contains multiple fields with repetitions.

any help will be much appreciated.

 

 

test.fmp12

test.xml

test.xsl

Posted

Try it this way:

<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 method="xml" version="1.0" encoding="UTF-8" indent="yes"/>

<xsl:template match="/">
  <JOB>
    <xsl:for-each select="fmp:FMPXMLRESULT/fmp:RESULTSET/fmp:ROW">
      <PrimaryKey><xsl:value-of select="fmp:COL[1]/fmp:DATA"/></PrimaryKey>
      <WTN><xsl:value-of select="fmp:COL[2]/fmp:DATA"/></WTN>
      <Customer><xsl:value-of select="fmp:COL[3]/fmp:DATA"/></Customer>
      <xsl:for-each select="fmp:COL[4]/fmp:DATA">
        <xsl:element name="Colours{position()}">
          <xsl:value-of select="."/>
        </xsl:element>
      </xsl:for-each>
    </xsl:for-each>
  </JOB>
</xsl:template>

</xsl:stylesheet>

 

Note:
Numbered elements are considered bad XML practice (just think how difficult it would be to process each color in a subsequent transformation).

This topic is 2265 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.