8 Replies Latest reply on Jun 17, 2017 6:16 AM by beverly

    Import SVG as XML using XSLT

    tmlutas

      I am trying to figure out how to import complex SVG graphics (up to several thousand paths in a particular file) and programmatically change elements (such as fill but not necessarily limited to that) based on calculations inside Filemaker. I'm trying to figure out how to parse an SVG file so that this is relatively easy. I will be modifying potentially a great many svg files this way.

       

      Is importing SVG as XML using multiple custom XSLT files a viable way to proceed? Or is it better just to load the whole thing and parse it out via script to the various records, do the changes, and then reassemble the SVG and export it?

       

      I'm not finding much discussion that's on point and if somebody's already done this I certainly don't want to reinvent the wheel.

        • 1. Re: Import SVG as XML using XSLT
          TomHays

          I don't know that importing the SVG into FileMaker fields is a useful way to approach the problem.  It all depends on what you intend to do specifically to the SVG contents and how that content is structured.  A FileMaker database may not be a useful tool.

           

          But XSLT may be a useful tool since it is designed to transform one XML file into another.  You can use FileMaker to apply an XSLT file to a source XML file without loading the data into FileMaker.

           

          If you put something like this

           

          <xsl:for-each select="document('MySourceSVG.xml')">

          <xsl:call-template name="modify_the_SVG"/>

          </xsl:for-each>

           

          into your XSLT file and export dummy information from FileMaker to XML, you can transform the XML you name using XSLT without loading the data into FileMaker.

           

          Of course, using FileMaker just to access the Xalan library (XSLT processor) is overkill, but it is obviously a tool you have at hand.

           

          -Tom

          1 of 1 people found this helpful
          • 2. Re: Import SVG as XML using XSLT
            beverly

            I have not done this, but you should be able to use one XSLT. The "data" changes in an SVG, but the basic tags are the same.

             

            Beverly

            1 of 1 people found this helpful
            • 4. Re: Import SVG as XML using XSLT
              tmlutas

              I was simplifying for the question because there's a lot of data handling that needs to go on that has nothing to do with SVG. The change data has to go into the database because it's likely to be calculated in multiple ways yielding different SVG mods depending on what you're looking for.

               

              I might have to change the fill on 3000 counties in the USA where each fill gets one of 8 different values depending on a calculation done within Filemaker. Then I might get a revision request to change to a different color scheme from the client which would change all the fill values. I want to be able to loop through ~3k records and generate SVG files visible in a web viewer so I can take screen shots and not go through this another 15 times, or even better, generate them all the first time around and routinely provide screen shots to avoid the usual back and forth. Oh, and I want to salt the data so that one random county is wrong by one shade in each preview, different county every variant.

               

              Inside Filemaker, I know how to make these changes work efficiently. XSLT, I'm not so comfortable with.

              • 5. Re: Import SVG as XML using XSLT
                tmlutas

                Those two weren't directly helper but right next to them was one that was much closer: https://dbservices.com/articles/heat-maps-in-filemaker/


                The problem is that the heat map won't usually be used in Filemaker. It's much more likely to be in a poster, a web page, on a news release, or multiple of the above so the icon technique in the video doesn't work. If there are going to be links, they're going to need to be xlinks within the SVG, not filemaker button scripts.

                 

                Then again, they might be in a Filemaker solution but using the FMP protocol means that's no problem. I can assemble the requisite map and just stick it in a field for use.

                 

                Does this make what I'm asking about clearer? I want a general solution that can be applied to any SVG and any attribute and there are a lot of those in the spec:

                SVG Attribute reference - SVG | MDN

                • 6. Re: Import SVG as XML using XSLT
                  beverly

                  Yes, you basically want a way to change some of the attributes in the SVG. And you can with XML/XSLT, but all SVGs are NOT going to have all those attributes.

                  You may be better off with a graphics program that allows you to easily change these attributes and return the finished SVG.

                  You'll get into HTML/CSS/JavaScript to make these have other functions.

                  Trying to use FM for this may not be as easy! You'll need to understand what you have and what you need.

                   

                  Beverly

                  • 7. Re: Import SVG as XML using XSLT
                    tmlutas

                    Could you point me to a graphics program that can easily take a list multi-thousand items long and change each attribute based on a calculation from a supplied separate list value?

                     

                    I've never seen anything like that, which is why I was looking at a database program. The graphics per se part, the vector path, is something that might change every few years or so as a political sovereign splits or changes an administrative border. The colors assigned function might be something that happens daily along with the color key and a bit of text description.

                     

                    I'm looking to start off changing one attribute, the fill attribute, with the ability to change other attributes being added subsequently (links, lines, background, etc). All the graphics people I've approached are enthusiastic at the beginning that exactly the approach you recommend is the way to go and then their faces fall at the scope of the work with the required error rate being zero and they look at me as if I were mad when I tell them the time constraints. Changing a few thousand variables with the graphics approach is a multi-day affair that they'd desperately look to automate with... scripts and a database or spreadsheet. I'd be happy if a map were done in an hour and I suspect a well done Filemaker solution would have a turnaround of significantly less than an hour to modify a US county level map and probably under a minute for a US state map.

                     

                    If I ever get to the point of census tract, all political districts, or zip plus four codes, the graphics solution entirely breaks. The database approach scales out far beyond national complexity even in the world's most complex political system, the USA.

                    • 8. Re: Import SVG as XML using XSLT
                      beverly

                      So, this sounds like "graphing" data points, perhaps?

                      Or you just might need to learn how to use XSLT to grab the elements & attributes to push to "data" that you can then allow "edits", then spit back out with another XSLT or calculated XML and use the script step Export Field Contents.

                      A place to start to "import" the xml:

                      This XSLT can be used to get some useful information on the XML you wish to read (SVG) into FileMaker.

                      I doubt you will find any "ready-made" solutions. Although there may be methods (not FileMaker) out there. You may need to search.

                      Beverly

                      1 of 1 people found this helpful