Jump to content

xml import from inconsistent amount of elements


demski

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

Recommended Posts

[Edit: added xslt example]

Hi all,

Given I have an xml like this:

 

<row1>

   <node1>text1</node1>

   <node2>text2</node2>

   <node3>text3</node3>

</row1>

<row2>

   <node1>text4</node1>

   <node3>text5</node3>

</row2>

 

Where node1..n are matched to fields 1..n accordingly, how do I force the xml-import to create an empty field2 at second row instead of putting the value of node3 into it?

 

I have tried constructs like this:

<xsl:choose>
  <xsl:when test="(/results/issues/issue/coverDate) or (not(/results/issues/issue/coverDate))">
     <xsl:for-each select="coverDate"> 
        <COL>
           <DATA>
              <xsl:value-of select="."/>
           </DATA>
        </COL>
      </xsl:for-each>
   </xsl:when>
   <xsl:when test="not(/results/issues/issue/coverDate)">
       <COL>
           <DATA>
           </DATA>
       </COL>
   </xsl:when>
</xsl:choose>
 
But this doesn't seem to work. At least it didn't throw any errors but a nonexistent 'coverDate' will drag the data from the next xml element into the 'coverDate' Field in FM.

 

TiA,

 

demski

Link to comment
Share on other sites

I am afraid this is impossible to follow.

results/issues/issue/coverDate

does not match a structure of:

<row1>
   <node1>text1</node1>
   <node2>text2</node2>
   ...

I suggest you post a complete example of your XML input, along with the entire stylesheet you have so far.

  • Like 1
Link to comment
Share on other sites

Thanks for your response!

Yeah, of course, you are right. I mixed exemplary with real world stuff.

Let me formulate it again as the xml I am working on contains customer data I am not supposed to show...

 

When importing an xml similar to the example below I receive a second record in FM that shows "text5" in field2 and an empty field3 instead of empty field2 and "text5" in field3.

I hope this was better asked? 

 

the xml should be:

<?xml version="1.0"?>
<rows>
    <row>
        <node1>text1</node1>
        <node2>text2</node2>
        <node3>text3</node3>
    </row>
    <row>
        <node1>text4</node1>
        <node3>text5</node3>
    </row>
</rows>

 

whereas the xslt would look like

 

 

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xsl:output method="xml" version="1.0" encoding="ISO-8859-1" indent="yes"/>
    <xsl:template match="/*">
        <FMPXMLRESULT xmlns="http://www.filemaker.com/fmpxmlresult">
            <ERRORCODE>0</ERRORCODE>
            <PRODUCT BUILD="11/1/03" NAME="" VERSION=""/>
            <DATABASE DATEFORMAT="M/d/yyyy" LAYOUT="" NAME="" RECORDS="{count(/*/row)}" TIMEFORMAT="h:mm:ss a"/>
            <METADATA>
                <FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="field1" TYPE="TEXT"/>
                <FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="field2" TYPE="TEXT"/>
                <FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="field3" TYPE="TEXT"/>
            </METADATA>
            <RESULTSET>
                <xsl:attribute name="FOUND">
                    <xsl:value-of select="count(/*/row)"/>
                </xsl:attribute>
                <xsl:for-each select="/*/row">
                    <ROW>
                        <xsl:for-each select="node1">
                            <COL>
                                <DATA>
                                    <xsl:value-of select="."/>
                                </DATA>
                            </COL>
                        </xsl:for-each>
                        <xsl:for-each select="node2">
                            <COL>
                                <DATA>
                                    <xsl:value-of select="."/>
                                </DATA>
                            </COL>
                        </xsl:for-each>
                        <xsl:for-each select="node3">
                            <COL>
                                <DATA>
                                    <xsl:value-of select="."/>
                                </DATA>
                            </COL>
                        </xsl:for-each>
                    </ROW>
                </xsl:for-each>
            </RESULTSET>
        </FMPXMLRESULT>
    </xsl:template>
</xsl:stylesheet>

Link to comment
Share on other sites

Okay, this is just because you are making this more complicated than it needs to be. Try it this way:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="utf-8" indent="yes"/>

<xsl:template match="/">

<FMPXMLRESULT xmlns="http://www.filemaker.com/fmpxmlresult">
<ERRORCODE>0</ERRORCODE>
<PRODUCT BUILD="" NAME="" VERSION=""/>
<DATABASE DATEFORMAT="" LAYOUT="" NAME="" RECORDS="" TIMEFORMAT=""/>

<METADATA>
    <FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="field1" TYPE="TEXT"/>
    <FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="field2" TYPE="TEXT"/>
    <FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="field3" TYPE="TEXT"/>
</METADATA>

<RESULTSET FOUND="">

<xsl:for-each select="rows/row">
<ROW MODID="" RECORDID="">
    <COL><DATA><xsl:value-of select="node1"/></DATA></COL>
    <COL><DATA><xsl:value-of select="node2"/></DATA></COL>
    <COL><DATA><xsl:value-of select="node3"/></DATA></COL>
</ROW>
</xsl:for-each>

</RESULTSET>
</FMPXMLRESULT>
</xsl:template>
</xsl:stylesheet>
  • Like 1
Link to comment
Share on other sites

Thanks a lot! I will give it a try on my full example and see what this will return then!

BTW: is

 

 

<RESULTSET FOUND="">

really enough or does it have to contain the count of elements? I thought that one was mandatory!

Link to comment
Share on other sites

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