Re: xslt

i had a good oreilley book, but since i bought it with CCS' dime, it's still at their offices. so here's my 5 minute "what is xslt":
conceptually it's ridiculously simple. it's sorta like a glorified microsoft mail merge template.
  "Dear {{first_name}} {{last_name}}
  BlahBlahBlah..."
where 'first_name' and 'last_name' are named xml nodes in the source file.
the part that makes xslt useful is that you can stick these XML nodes into things other than just plain text form letters to your adoring fans. you can stick those nodes into other types of code. for example, if you were taking an xml data dump from one source and loading it into another database that used "given_name" instead of "first_name" and "surname" instead of "last_name", you could envision an xslt like this:

<xslt>
<given_name>{{first_name}}</given_name>
<surname>{{last_name}}</surname>
</xslt>

when you "execute" the xslt, you tell it "here's the source xml, here's the xslt transfom template, and here's where i want the resulting file to go". that file might look something like this:
<xml>
<given_name>brian</given_name>
<surname>kusler</surname>
</xml>
<xml>
<given_name>nina</given_name>
<surname>ramos</surname>
<xml>
(and so on, one for each entry in the source file)
and of course you can do all kinds of tricky things too-- you can actually use the template to produce output in PDF or any format you want, as long as you're nerdy enough to write the transform correctly :)
there are GUI-based tools for doing xslt development, but i've never used any of them, i just do it all from the command line. i use xalan from apache for that ( http://xml.apache.org/ ). one look at that page and you'll understand why the CCS billing engine is called Xena. :)
i use the java version of xalan. an example call from the command line:
java org.apache.xalan.xslt.Process -in BUScat.xml -out BUScred.iif -xsl quickbooks_cred_group.xsl -TEXT
pretty straightforward... arguments are in pairs (e.g., -in followed by the input filename) the final -TEXT argument tells it that you want the output file in plain .txt format. (TIP: if you're using a mac, typing open filename.txt at the command line will open the file in the finder using that file's default editor).
as i'm sure you know, xml is rarely a big, flat structure. it's often composed of nested elements.

<xml>
 <person>
   <given_name>brian</given_name>
   <surname>kusler</surname>
 </person>
 <person>
  <given_name>nina</given_name>
  <surname>ramos</surname>
 </person>
</xml>
the art of telling the xslt what you really want it to select is an art in and of itself (called xpath). it can be as simple as "person/given_name" but there's all kinds of fun jedi type ways to select nodes.
some helpful links:

On Aug 31, 2007, at 11:29 AM, Nina wrote:
school me!

resources I should look at? tutorials I should go through?
keep in mind, I don't even write xml from scratch - I mine it from others and modify it to meet my needs.


good deep fry! my belly is still full...


-Neens

Comments

Post a Comment

Popular Posts