Jump to content

Help with XML stylesheet?


TLIEB

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

Recommended Posts

I have been given the task of trying to import our postal information which we receive as XML files into Filemaker. I've been searching the forums for the last few days and I've found several examples which I've tried to build off, but I'm still not doing something right. We have no experience working with XML files so I can't quite figure out where I'm going wrong.

When I try to import my XML file into Filemaker using the stylesheet I created, It looks like all the fields are mapping right, but I don't get data in any of the fields. I get the following pop up message:

importsummary.png

 

This is the stylesheet I have built so far, the sample XML data we were provided is attached. Can anyone point me in the right direction as far as what my problem is and what I need to fix? As an aside, I know I have the CustomerReferenceID field importing twice. Given the sample data we received we're not quite sure which fields we will actually need to import so I'm using one of those entries as a placeholder.

<?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=""/>
 
  <!-- DEFINE FIELDS -->
  <METADATA>
   <FIELD NAME="Mail Date" TYPE="TEXT" EMPTYOK="YES" MAXREPEAT=""/>
   <FIELD NAME="Customer Reference ID" TYPE="TEXT" EMPTYOK="YES" MAXREPEAT=""/>
   <FIELD NAME="Job Description" TYPE="TEXT" EMPTYOK="YES" MAXREPEAT=""/>
   <FIELD NAME="Permit" TYPE="TEXT" EMPTYOK="YES" MAXREPEAT=""/>
   <FIELD NAME="Total Postage" TYPE="NUMBER" EMPTYOK="YES" MAXREPEAT=""/>
   <FIELD NAME="Postage Affixed" TYPE="NUMBER" EMPTYOK="YES" MAXREPEAT=""/>
   <FIELD NAME="Net Postage" TYPE="NUMBER" EMPTYOK="YES" MAXREPEAT=""/>
   <FIELD NAME="Quantity" TYPE="NUMBER" EMPTYOK="YES" MAXREPEAT=""/>
   <FIELD NAME="Affixed Amount" TYPE="NUMBER" EMPTYOK="YES" MAXREPEAT=""/>
   <FIELD NAME="Metered-Stamped" TYPE="NUMBER" EMPTYOK="YES" MAXREPEAT=""/>
  </METADATA>
 
  <!-- IMPORT DATA -->
  <RESULTSET FOUND="">
   <xsl:for-each select="PostageStatement">
    <ROW MODID="" RECORDID="">
     <COL><DATA><xsl:value-of select="ClosingDate"/></DATA></COL>
     <COL><DATA><xsl:value-of select="CustomerReferenceID"/></DATA></COL>
     <COL><DATA><xsl:value-of select="CustomerReferenceID"/></DATA></COL>
     <COL><DATA><xsl:value-of select="PermitNumber"/></DATA></COL>
     <COL><DATA><xsl:value-of select="TotalUSPSAdjustedPostage"/></DATA></COL>
     <COL><DATA><xsl:value-of select="PostageAffixed"/></DATA></COL>
     <COL><DATA><xsl:value-of select="NetPostageDue"/></DATA></COL>
     <COL><DATA><xsl:value-of select="TransactionAmount"/></DATA></COL>
     <COL><DATA><xsl:value-of select="RatePostageAffixed"/></DATA></COL>
     <COL><DATA><xsl:value-of select="PermitType"/></DATA></COL>
    </ROW>
   </xsl:for-each>
  </RESULTSET>
</FMPXMLRESULT>
</xsl:template>

</xsl:stylesheet>

xml.zip

Link to comment
Share on other sites

There are two major problems with your stylesheet:

First, your XML source places all its elements in a namespace: xmlns="http://www.windowbook.com/pwnedoc/1.0". To select such elements by their name, you must use a fully-qualified name.  That means declaring the namespace in your stylesheet, assigning it a prefix, and using this prefix when addressing the elements in the source document.

The second problem is that your template puts you in the context of the / root node. From this context, the instruction:

<xsl:for-each select="PostageStatement">

does not select anything, because PostageStatement is not a child of the current node.

Here is your stylesheet with the two major flaws corrected (and some redundant nodes removed):

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

<xsl:template match="/wb:PostageStatements">
  <FMPXMLRESULT xmlns="http://www.filemaker.com/fmpxmlresult">
    <!-- DEFINE FIELDS -->
    <METADATA>
      <FIELD NAME="Mail Date" TYPE="TEXT"/>
      <FIELD NAME="Customer Reference ID" TYPE="TEXT"/>
      <FIELD NAME="Job Description" TYPE="TEXT"/>
      <FIELD NAME="Permit" TYPE="TEXT"/>
      <FIELD NAME="Total Postage" TYPE="NUMBER"/>
      <FIELD NAME="Postage Affixed" TYPE="NUMBER"/>
      <FIELD NAME="Net Postage" TYPE="NUMBER"/>
      <FIELD NAME="Quantity" TYPE="NUMBER"/>
      <FIELD NAME="Affixed Amount" TYPE="NUMBER"/>
      <FIELD NAME="Metered-Stamped" TYPE="NUMBER"/>
    </METADATA>
    <!-- IMPORT DATA -->
    <RESULTSET>
      <xsl:for-each select="wb:PostageStatement">
        <ROW>
          <COL><DATA><xsl:value-of select="wb:ClosingDate"/></DATA></COL>
          <COL><DATA><xsl:value-of select="wb:CustomerReferenceID"/></DATA></COL>
          <COL><DATA><xsl:value-of select="wb:CustomerReferenceID"/></DATA></COL>
          <COL><DATA><xsl:value-of select="wb:PermitNumber"/></DATA></COL>
          <COL><DATA><xsl:value-of select="wb:TotalUSPSAdjustedPostage"/></DATA></COL>
          <COL><DATA><xsl:value-of select="wb:PostageAffixed"/></DATA></COL>
          <COL><DATA><xsl:value-of select="wb:NetPostageDue"/></DATA></COL>
          <COL><DATA><xsl:value-of select="wb:TransactionAmount"/></DATA></COL>
          <COL><DATA><xsl:value-of select="wb:RatePostageAffixed"/></DATA></COL>
          <COL><DATA><xsl:value-of select="wb:PermitType"/></DATA></COL>
        </ROW>
      </xsl:for-each>
    </RESULTSET>
  </FMPXMLRESULT>
</xsl:template>

</xsl:stylesheet> 

The rest has to do with the mapping of source nodes to output fields. I am afraid we don't have enough information to help with that.

 

Edited by comment
Link to comment
Share on other sites

You could very well be correct...however if we had an IT department in theory I would have never gotten handed this project to begin with since it has nothing to do with my department or my job, just the fact that I "know my way around computers a little".

  • Like 1
Link to comment
Share on other sites

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