[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Disjunctive reasoning in XSLT: controlling presen

Subject: Re: Disjunctive reasoning in XSLT: controlling presence of subtrees
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Fri, 20 Apr 2007 20:29:46 +0100
Re:  Disjunctive reasoning in XSLT:  controlling presen
Ken,

This works fine.  The difficulty arises from the fact that the input
data (a given row) can be quite variable:  An auto policy might have one
driver, or five, might cover one vehicle or 7, there might be no prior
accidents or violations, or several, etc., etc.  The naive transform
that I currently generate takes an expansive approach, setting up XML
subtrees for most everything that might possibly be coming through in
the data.  This has the effect of leaving essentially empty subtrees
throughout the target ACORD tree, which is not acceptable.  I currently
perform a post-process tree walk to clean up.  However, I'd like to
understand if it is possible to more intelligently generate an XSLT
transform which can omit various subtrees when the data for them is not
present.

I don't think you should be particularly wary of using a multi-step process: using pipelines means the individual transformations are a lot simpler, easier to maintain and debug.


But if you wanted to do it one pass, what about putting the prospective children of an element in a variable and only creating the element if the variable actually holds something? The templates you generate would look something like:

<xsl:template match="colname">
  <xsl:variable name="children" as="element()*">
    <!-- Code for generating the children goes here -->
  </xsl:variable>
  <xsl:if test="exists($children)">
    <newElement>
      <xsl:sequence select="$children" />
    </newElement>
  </xsl:if>
</xsl:template>

Cheers,

Jeni
--
Jeni Tennison
http://www.jenitennison.com

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.