Subject: Re: [xsl] Variations in XML to CSV From: Brandon Ibach <brandon.ibach@xxxxxxxxxxxxxxxxxxx> Date: Thu, 21 Apr 2011 13:53:12 -0400 |
As Michael pointed out, your next step should probably be to formalize your input and output samples into a set of requirements. It's a step that probably isn't done often enough in software development and can be particularly valuable when you're uncertain about where to begin in the coding process. Getting it all down in writing, in detail, can often clarify what needs to be done. Based on your samples, you might have requirements like: 1. The transform's output shall be plain text. 2. The transform's first output shall be the string "title,subject,creator,creator,contributor,contributor,subject,subject,subjec t,date", followed by a newline character. 3. For each "metadata" element in the input, the transform shall output a series of 10 fields, with each field followed by a comma except the last, which shall be followed by a newline character. 4. The first field shall consist of the content of a "title" element in the "metadata" element, if one exists, otherwise nothing. 5. The second field shall consist of the content of the first "subject" element that does not follow a "creator" or "contributor" element in the "metadata" element, if one exists, otherwise nothing. ...and so on. Note that requirement 5 was written under the assumption that a subject preceding the creator and contributor list is special and different from those that follow later. Written in enough detail, these can be translated quite readily into code. For instance, see how this requirement lines up with the following, which might appear inside a template for the "metadata" element: <xsl:variable name="subject1" select="subject[not(preceding-sibling::*[self::creator | self::contributor])][1]"/> -Brandon :) On Thu, Apr 21, 2011 at 10:53 AM, Bridger Dyson-Smith <bdysonsmith@xxxxxxxxx> wrote: > Hi Michel, > thanks for the reply! > >> Its hard to say when you don't provide an output sample. I guess order >> is important etc. > > I'm sorry that I can't provide an output sample - I don't know how to > generate one, but it might look something like this: > > title,subject,creator,creator,contributor,contributor,subject,subject,subject ,date > Alpha,Sinister,Beta,,,,Gamma,Delta,Epsilon,2011-04-19 > Zeta,,Eta,Theta,Dexter,Iota,Kappa,Lambda,,2011-04-19 > > >> Maybe you need to take several steps. Like determine how mayn subject >> elements you have max etc. Then maybe sort your input so all same >> named elements are consecutive. And then generate as many as you have >> for each element padding with empty items when you have run through. >> >> Michel > > Thank you for the suggestions - I'll look into regenerating the XML so > it's sorted & has blank elements where necessary. > Bridger
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Variations in XML to CSV, Michel Hendriksen | Thread | Re: [xsl] Variations in XML to CSV, Bridger Dyson-Smith |
Re: [xsl] break-before="odd-page" a, Brandon Ibach | Date | [xsl] Using XSLT to do a search & r, Bubba O'Reily |
Month |