- From: David A. Lee <dlee@calldei.com>
- Date: Mon, 15 Jun 2009 08:34:38 -0400
- To: "Costello, Roger L." <costello@mitre.org>
- CC: "xproc-dev@w3.org" <xproc-dev@w3.org>
This is a great question and applies to "Scripting" in general ( a topic of which I am fond). In the space of "traditional" scripting languages the answer of "best" is usually meant "most efficient" or "fastest to execute". Thats because "scripts" tend to be "slow". In a traditional scripting language which implements its steps as subprocesses, as long as the actual operations are quick, optimizing a script means to minimize the number of subprocess creations. Thus the answer in the case you present would be "put as much as possible OUTSIDE the script" (in your case xslt or schematron). Furthermore, in traditional scripting languages, the script execution itself tended to be less efficient then a highly tuned C program, further leading one to try to put as little in the script as possible. That is, if "best" means "runs fastest". But with scripting languages like XProc, which runs within the same JVM as most of its steps, and actually uses the same underlying engines for many of its features (such as xpath) as the steps themselves use, the Performance issue inst such a major issue. There may be cases where one language would perform the same tasks faster due to the maturity of that implementation or some native feature which can be leveraged (say something complex in XSLT vs XProc), but overall, I believe the performance aspects are less important in making decisions in XProc on how to write a "script". Which leads it much more open (and philosophically interesting) to decide "which is best". There are some degenerate cases (such as if the entire xproc script can easily be written in another language like XSLT then why use xproc at all, or the opposite where the operations are so difficult to write in xslt that you have no choice but to do them in a scripting language). But the middle cases are more interesting (IMHO). When a problem can be reasonably (and equivalently) solved in multiple ways which is "Best". I'll stop there. I think this is like asking if Chocolate or Vanilla (or perhaps more accurately "Rocky Road") is "best" but I'd love to hear some divergent opinions. David A. Lee dlee@calldei.com http://www.calldei.com http://www.xmlsh.org 812-482-5224 Costello, Roger L. wrote: > Hi Folk, > > One way to implement an XProc pipeline is to simply call XSLT (using p:xslt) and have a stylesheet do the work. Or, call Schematron to do the work. > > Alternatively, the work could be done using the basic XProc steps. > > What's best practice? Should the basic XProc steps be favored over escaping to XSLT or Schematron? > > EXAMPLE > > When processing an auto loan application it is necessary to determine if the applicant is underage. A person is underage depends on which (U.S.) state he/she resides in - in Alaska someone is underage if they are under 16 years of age, whereas in Ohio a person is underage if they are under 18 years of age. > > Determining whether an applicant is underage could be implemented using XSLT. It could be implemented using Schematron. And it could be implemented using the basic XProc steps. > > Here is an XSLT implementation: > > http://www.xfront.com/xproc/automated-decision-support/Is-Applicant-Underage.xsl > > Below is an implementation using the XProc steps. > > Suppose Fred creates an XProc pipeline for processing the loan application. When it comes time to determine if the applicant is underage he uses p:xslt to invoke an XSLT stylesheet that implements the "is underage" functionality. > > Suppose Sally also creates an XProc pipeline for processing the loan application. When it comes time to determine if the applicant is underage she uses the below user-defined XProc step to implement the "is underage" functionality. > > Which pipeline implementation is better - Fred's or Sally's? > > Why? > > /Roger > > > *************************************************** > User-Defined XProc Step to Determine > if a Loan Applicant is Underage > *************************************************** > <p:declare-step type="applicant:is-underage" > name="is-underage"> > > <p:input port="auto-loan-application" /> > <p:output port="result"/> > > <p:choose> > <p:variable name="state" select="Loan-Application/Applicant/Address/State" /> > <p:variable name="age" select="Loan-Application/Applicant/Age" /> > > <p:when test="($state eq 'AK') and (number($age) le 16)"> > <p:identity> > <p:input port="source"> > <p:inline><is-underage>true</is-underage></p:inline> > </p:input> > </p:identity> > </p:when> > <p:when test="($state eq 'AL') and (number($age) le 18)"> > <p:identity> > <p:input port="source"> > <p:inline><is-underage>true</is-underage></p:inline> > </p:input> > </p:identity> > </p:when> > <p:when test="($state eq 'AZ') and (number($age) le 17)"> > <p:identity> > <p:input port="source"> > <p:inline><is-underage>true</is-underage></p:inline> > </p:input> > </p:identity> > </p:when> > <!-- ... --> > <p:when test="($state eq 'OH') and (number($age) le 18)"> > <p:identity> > <p:input port="source"> > <p:inline><is-underage>true</is-underage></p:inline> > </p:input> > </p:identity> > </p:when> > <!-- ... --> > <p:when test="($state eq 'WY') and (number($age) le 17)"> > <p:identity> > <p:input port="source"> > <p:inline><is-underage>true</is-underage></p:inline> > </p:input> > </p:identity> > </p:when> > <p:otherwise> > <p:identity> > <p:input port="source"> > <p:inline><is-underage>false</is-underage></p:inline> > </p:input> > </p:identity> > </p:otherwise> > </p:choose> > > </p:declare-step>
Received on Monday, 15 June 2009 12:35:28 UTC