CRoberts Posted January 9, 2008 Posted January 9, 2008 (edited) Hi I am still stuck trying to work out how to create an XSLT from an XML file output via one of our custom systems. XML is: <?xml version="1.0" encoding="utf-8"?> project_key="PR0001" project_title="Brochure" client="A Publisher"> key="000001" name="Project stage of work" start_date="2008-01-08" end_date="2008-01-30" support_person="A Person" resources="{List of people}" project_manager="pm"/> -- end Any help on creating an XSLT would be very much appreciated. Regards C Edited January 10, 2008 by Guest
CRoberts Posted January 31, 2008 Author Posted January 31, 2008 Something clicked and so I've been trying to get my head around the msdso_attrib.xslt example. I do not understand how the "select" statement works (not the SQL SELECT statement ;-) as in: "Notice the complex select statement used to handle each of the attributes in the XML input file." So where it shows: I do not see how this matches to the xml field data: Can anyone help or point me at some documentation that explains this in more detail? Regards
Fenton Posted January 31, 2008 Posted January 31, 2008 I don't have that example file in front of me. But basically an asterisk is a "wild card", which will match anything at that level. The "/" slashes determine the level. It's a somewhat loose way to select data. Brackets with a number in them specify an occurrence (like in the FileMaker Position() function). /*/*[1]/@* Means (I think), within the 1st element of the 1st node at the 2nd level down from the root, get all the attributes. In this case it gets: PR0001 Brochure A Publisher (I put returns between them, otherwise they'd just be mushed together; xsl has no "separators," unless you add them.)
CRoberts Posted February 1, 2008 Author Posted February 1, 2008 Fenton Thanks, makes sense. What if , as in my example data at the top, I have two elements: Project and Stage. Any ideas how I then adjust to allow for more than one element on the 2nd level? Cheers
Fenton Posted February 1, 2008 Posted February 1, 2008 You could take out the [1]. But it's there for a reason. I found the "msdso_attrib.xslt" example and looked at it. There are two sections in that xsl file. The first section, with the [1] is there to build the "metadata" node-set for the FileMaker fields. It is required to tell FileMaker what the fields are when you Import. The xsl only needs to do this once, so it targets only the first element. It is pulling this from the attribute names (not the values), using the xsl name() function. If you look further down you will see the section that is actually getting the data for the fields. It does not have [1]. The example xsl will get the multiple elements' (people in its case) attributes. In your case that just gets the attributes of multiple Projects, it doesn't get the Stage of each. Stage is a child of Project. Would it then be a separate table in FileMaker? It should be if there are possibly multiple Stages. This is a critical question before writing the xsl, as it would be separate xsl file (similar to the first).
CRoberts Posted February 1, 2008 Author Posted February 1, 2008 You're right. Projects do have multiple stages. Best then to import Project and Stage data in separate steps. I guess I can refer to Stage data by adding in another layer. XPath gives impression i can use name of element node, so shouldn't this work? .. .. .. Thanks for your help.
Fenton Posted February 1, 2008 Posted February 1, 2008 Well, the thing is, if Stages is a separate table, as is "relationally correct" (RC, like PC, "politically correct" -), then it's 2 Imports, which means 2 xsl files, one for Projects, one for Stages, both very similar, but with Stages matching the next node down. However, one addition to the Stages xsl is to reach "up" one node, and get the "project_key" attribute. This is the ID field that would tie the Project import to its Stages. You would also need to add that as a Field in the Metadata section. The way it is being done in the msdso_attrib.xslt is very clever and generic, using the wild-card symbol to match elements at the level. The same method can be used to get the project_key, as it is the 1st attribute of the 1st Project. Though, as you said, you can also specify things by their name, instead of being generic. Attached is a modified version of the msdso_attrib.xslt file, to get the Stages, along with the project_key. I left all the other text in, as it is required. msdso_attrib_Stages.xslt.zip
Fenton Posted February 1, 2008 Posted February 1, 2008 P.S. You might want to look at this in a real text editor, such as BBEdit, or it's (free) little brother, TextWrangler, from http://www.barebones.com Or an xml editor.
Recommended Posts
This topic is 6140 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 accountSign in
Already have an account? Sign in here.
Sign In Now