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

Creating xslt for an existing xml


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

Recommended Posts

Posted

Hello all,

I'm new to xml and was trying to find out if there is an easy way to generate an xslt from an existing xml, for FMP.

Any hints or comments?

Posted

Short answer: no easy way. XML means "Extensible Markup Language" for a reason, which is that anyone can create their own xml elements to describe their data, unlike HTML, which has mostly fixed elements

FileMaker for example has its own xml requirements, which are a bit more extensive than most simple xml files. It wants many things defined, such the database, the fields and their type (TEXT, NUMBER, DATE, etc.). Since xml you get from anywhere other than a FileMaker xml export is not likely to have this info included, you have to add it yourself. The mechanism for adding info and data, also extracting and arranging it is XSL,"Extensible Stylesheet Language."

You can see the form required by exporting XML from FileMaker, with FMXMLRESULT as the type of xml; but no XSL file selected. You can then basically copy most of the top of that to an XSL file to get what's needed for those topmost elements. An XSL file also needs an element as its "root" element (every XML document must have a root element, and an xsl file is a kind of xml file).

The data from FileMaker is (usually) in the structure:

some data

some other data

So, if your original XML file doesn't include those, you need to add them in the XSL file. You write "XPath" instructions to select the data from the xml for "some data", etc..

That's the general overview. I'm no XML expert, and you don't need to be one to do simple Import XML and Export XML. But you need to know much more than for other types of FileMaker Imports. Look at one of the simpler examples from the FileMaker site's XML area (most of them are not simple). Or do a search here in the XML forum.

Posted

Thanks for the reply.

I think it would be enlightening to look at an example, for instance, like Apple's iPhoto Album.xml

All OSX users have this if they've ever used iPhoto.

I notice there is a file location element, several array elements describing structure, and of course the individual photo information.

I've looked at earlier implementations, when the info was in seperate files, but now it's pretty much monolithic and I wouldn't be sure of where to start.

I'll eventually be working with a different application altogether, but I think the output will be similar in construction.

Posted

Apple's implementation of xml is going to be a bit different from what you'd normally see in the business world. It is more abstract. They've come up with a generic way of structuring xml so that it can handle all different kinds of data in more or less the same structure, with a root element of "plist." The way they do this is by using a well-known structure of generic names for the elements themselves, then putting the name of what the data is as data within one of these generic containers.

This is how many preference files are stored in OS X (though I believe more are going into binary files in Tiger).

This is a stripped down example from iPhoto. I've removed the entire top subsection of Application and Albums data, leaving only the "Master Image List", with 2 photos:

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

Application Version

3.0 (4B9)

List of Albums

Master Image List

61

Caption

california_palomar_1024

Aspect Ratio

1.333333

DateAsTimerInterval

139533772.000000

ImagePath

/Users/fej/Pictures/iPhoto Library/2005/06/03/california_palomar_1024.jpg

ThumbPath

/Users/fej/Pictures/iPhoto Library/2005/06/03/Thumbs/61.jpg

62

Caption

earthterminator_1024

Aspect Ratio

1.333333

DateAsTimerInterval

140307915.000000

ImagePath

/Users/fej/Pictures/iPhoto Library/2005/06/12/earthterminator_1024.jpg

ThumbPath

/Users/fej/Pictures/iPhoto Library/2005/06/12/Thumbs/62.jpg

It's fairly simple to extract the data. The "field name" is in a element, with the data in the next element. You do NOT however know what the data element is going to be; could be , could be , , . But you do know that it is the next. So you can use this XPath for each piece of the data itself:

You'll likely not find this kind of generic structure in most business xml.

(P.S. I included a .work file, from TestXSLT, which is a free OS X app to test your transformations, very handy.)

iPhoto_XML.zip

Posted

Abstract answer to an abstract question: There is a tool around, Altova MapForce, where you can map a source XML grammar/file to a target XML grammar/file, and an XSLT file is created. The other question is if the generated XSLT code is a understandable and further manageable.

It's pretty expensive, but there is a 30 day trial version available at http://www.altova.com/download_mapforce_standard.html

It's only available for Windows.

Posted

A further problem, which we haven't really mentioned in this thread so as not to complicate matters any further, is that FileMaker is a relational database, with multiple tables, and an xml file is often also "relational", because it can have several "levels" of data.*

Just as it would be between 2 relational database files, it is also true with a multi-table FileMaker file and an multi-level XML file. You would often want to import the XML into different tables, each import getting the correct data into the correct table. This usually means a separate XSL file for each import. The structure of each shares some similarities (namespaces, database name, etc.), but is different also.

This is not actually a big deal. And it tends to make each xsl file simpler, as it only has to deal with its own data, ignoring the rest.

*For example I ignored the "Albums" in the iPhoto import, only getting the "flat" data of the pictures themselves.

Posted

Aaah. Thanks for the example, hints, and sample software. I understood about the relational aspect of the data and I'm already fairly far along with the FMP part of the puzzle.

The reason I picked iPhoto was specifically because I understood the array nature of the data and it gives me a straightforward model to pick apart. The data, and structure, for my customer is considerably different. I may try the demo software and see what it produces as a starting point.

Thanks again.

Posted

You might want to look at the Amazon XML example I posted a few days ago, and some others posted here. They are more "business" type xml/xsl. I don't know that any of them is "relational" however; multiple Imports (perhaps, I can't remember). But, as I said, it's not a big deal. If you can do one xml/xsl import you can generally do another from the same xml file without too much trouble. It's mostly in the XPath selection, which is a flexible and powerful mechanism.

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