Gmail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
Message from discussion TclXSLT question: best approach?
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
John Seal  
View profile  
 More options May 30 2005, 3:08 pm
Newsgroups: comp.lang.tcl
From: John Seal <se...@indy.raytheon.com>
Date: Mon, 30 May 2005 14:08:32 -0500
Local: Mon, May 30 2005 3:08 pm
Subject: TclXSLT question: best approach?
I'm prototyping an app that uses XML config files.  This morning I knew
just enough XML to ask stupid questions, and even less about XSL.  But
with a little help from O'Reilly's "XML Hacks" (the Socket Wrench book)
and w3.org I learned quite a bit.

My goal was to convert an XML file defining a series of nodes, each with
six attributes, into a list of lists, with the attributes in the inner
lists in a standard order regardless of their order in the XML.  (I was
surprised how many quick & dirty solutions just copy things in document
order, which seems like asking for trouble!)  I created an .xsl file
that performed the transform, which I tested by opening the .xml file in
a browser.  Woo hoo, the transform works!

Then I used tclXSLT to do it in Tcl thusly (where $xml and $xsl are the
contents of the respective files):

package require dom
package require xslt
set xmldoc [::dom::libxml2::parse $xml]
set xsldoc [::dom::libxml2::parse $xsl]
set listify [::xslt::compile $xsldoc]
set txtdoc [$listify transform $xmldoc]
set bands [::dom::libxml2::serialize $txtdoc -method text]

That works, so obviously I've found *a* way, but when venturing into
unknown territory I like to keep to the *right* way as much as possible.

One question that arose immediately was why do I have to say "-method
text" when the XSL already specifies <xsl:output method="text" />?  I
guess for no other reason than that the man page says I have to, huh?

The other question is one of the whole approach.  Having a separate .xsl
file makes it easy to view the XML files in a browser, which is
potentially useful.  But I could have just walked the XML doc tree in
Tcl, pulling out attributes and stuffing them in a list.  In fact, the
code to do this would look a lot like the templates in the .xsl file.

How would the Tcl/XML/XSL graybeards do this?

(I am a mere salt&pepperbeard.)


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google