6 Replies Latest reply on Sep 27, 2016 10:41 AM by beverly

    XSLT Question Regarding XML Import

    user25627

      Hi there,

       

      I'm trying to Import XML documents by way of an XSLT file into Filemaker. Most nodes work just fine, however, for the highlighted node "CONT" I want to Import everything between the <CONT> and </CONT> tags incl. markup etc. This I didn't manage so far.

       

      Any help is very much appreciated!

      Pete

       

      XML source document

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

      <UnitXml>

      <HEAD>

        <PTO>

         <CPN>850</CPN>

         <CO>US</CO>

        </PTO>

      </HEAD>

      <BODY>

        <PPICONTAINER>

         <PPI>

          <VP>22</VP>

          <JC>02</JC>

          <CF>00</CF>

          <CONT>

           <Double/>

           <space/>

           <space/>

           <space/>

           <space/>

           <StartBox/>

           <StartBox/>

           Text

           <EndBox/>

           <EndBox/>

          </CONT>

         </PPI>

         <PPI>

          <VP>20</VP>

          <JC>02</JC>

          <CF>00</CF>

         <CONT>

           <Double/>

           <StartBox/>

           <StartBox/>

           Welcome

           <space/>

           to

           <space/>

           the

           <space/>

           &quot;US&quot;.

           <EndBox/>

           <EndBox/>

           <newline/>

           <newline/>

           <Double/>

           <space/>

           <space/>

           <space/>

           <space/>

           <space/>

           <StartBox/>

           <StartBox/>

           Hello again.

           <EndBox/>

           <EndBox/>

          </CONT>

         </PPI>

         </PPICONTAINER>

      </BODY>

      </UnitXml>

       

      XSLT document

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

      <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

      <xsl:template match="/">

        <FMPXMLRESULT xmlns="http://www.filemaker.com/fmpxmlresult">

         <METADATA>

          <FIELD NAME="CPN" TYPE="TEXT"/>

          <FIELD NAME="CO" TYPE="TEXT"/>

         </METADATA>

         <RESULTSET>

         <xsl:for-each select="/StlXml/BODY/TTICONTAINER/TTI">

          <ROW RECORDID="" MODID="">

           <COL>

            <DATA>

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

            </DATA>

           </COL>

           <COL>

            <DATA>

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

            </DATA>

           </COL>

           <COL>

            <DATA>

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

            </DATA>

           </COL>

           <COL>

            <DATA>

             <xsl:copy-of select="CONT??????????????????"/>

            </DATA>

           </COL>

          </ROW>

         </xsl:for-each>

         </RESULTSET>

        </FMPXMLRESULT>

      </xsl:template>

      </xsl:stylesheet>

        • 1. Re: XSLT Question Regarding XML Import
          fmpdude

          Before trying something like this in FM, I would recommend (if you haven't already) that you use a real XML tool like Oxygen (mac/windows), or similar, to make sure your XSLT works as expected with your document.

           

          Make sure it's not an XSLT issue first.

           

          HOPE THIS HELPS.

          • 2. Re: XSLT Question Regarding XML Import
            beverly

            a handy XSLT to use to make sure your XPaths are correct:

             

            1. your source XML has: PPI/CONT

            2. your XSLT appears to have: TTI/CONT

                 so your for-each is also incorrect

            3. your XSLT has two FIELD elements (into which the data will import), but four COL/DATA sets, so this is a mis-match

            4. your usage of 'xsl:copy-of' appears to be ok, but you do know you just get a chunk of XML into the one field, right? are you further parsing?

             

            Try the above XSLT to help you understand what you have.

            beverly

            2 of 2 people found this helpful
            • 3. Re: XSLT Question Regarding XML Import
              user25627

              Hi fmpdude,

               

              Thanks for this suggestion -- that's what I did, but do not manage to transfer the approach into a XSLT working with FM ...

              • 4. Re: XSLT Question Regarding XML Import
                user25627

                Hi beverly,

                 

                Thanks a lot for your extremely helpful comments!

                 

                By simplifying my real world case into something simple to grasp some errors where introduced. I've double checked the sample code and corrected it (see attachments).

                 

                The import of my fields "VP", "JC" and "CF" work just fine, however, I still don't manage to get everything (incl. markup) from the "CONT" field. I cannot see any difference between using <xsl:copy-of select="CONT"/> and <xsl:copy-of select="CONT/node()"/>. Yes, I do want the text with markup in the FM field "CONT" to do further parsing inside FM.

                 

                "CONT" value of the first imported record in FM

                 

                 

                 

                 

                 

                 

                    Text

                 

                 

                    "

                I would want for the value of the first record instead:

                 

                "     <Double/>

                     <space/>

                     <space/>

                     <space/>

                     <space/>

                     <StartBox/>

                     <StartBox/>

                     Text

                     <EndBox/>

                     <EndBox/>"

                 

                "CONT" value of the second imported record im FM

                "

                 

                 

                 

                    Welcome

                 

                    to

                 

                    the

                 

                    "US".

                 

                 

                 

                 

                 

                 

                 

                 

                 

                 

                 

                 

                    Hello again.

                 

                 

                 

                "

                 

                And here I would want:

                 

                "

                     <Double/>

                     <StartBox/>

                     <StartBox/>

                     Welcome

                     <space/>

                     to

                     <space/>

                     the

                     <space/>

                     &quot;US&quot;.

                     <EndBox/>

                     <EndBox/>

                     <newline/>

                     <newline/>

                     <Double/>

                     <space/>

                     <space/>

                     <space/>

                     <space/>

                     <space/>

                     <StartBox/>

                     <StartBox/>

                     Hello again.

                     <EndBox/>

                     <EndBox/>"

                 

                Thanks all your help!

                Pete

                • 5. Re: XSLT Question Regarding XML Import
                  CamelCase_data

                  beverly is the expert here, but it looks to me like what you want isn't a "real" xml import. An xml import normally imports just the data from the xml, but what you want is to do a mix of importing data and xml tags. 

                  You may be better off using a scripted procedure and parse the text you want to, and then loop to crete the records and write the values. There are a number of custom functions that will allow you to do so relatively easily.

                   

                  http://fmfunctions.com/functions_display_record.php?functionId=110 is a good place to start.

                  • 6. Re: XSLT Question Regarding XML Import
                    beverly

                    thanks, but I'm trying to recall if copy-of ever worked for "import". I would be 10+ years to look back through.

                     

                    a CF or plug-in may help here, for sure.

                     

                    But try the generic XSLT I posted about earlier and tell us what you get:

                     

                    beverly