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

Tricky one

Subject: Tricky one
From: "Curtis Burisch" <curtis@xxxxxxxxxx>
Date: Thu, 22 Aug 2002 13:53:23 +0100
tricky one
Hi,

(apologies if you're getting this twice, I think the first one didn't get
through. If you've replied to this already please send me a copy? having
problems with the list.)

I'm faced with a problem that for the life of me I can't figure out how to
solve.

Scenario:

XML:

<root>
  <abc>
    <def>
      <ghi>FRED</ghi>
      <ghival>23</ghival>
    </def>
    <def>
      <ghi>ANDY</ghi>
      <ghival>96</ghival>
    </def>
  </abc>
</root>

XSLT:

(pseudo-code)
if root/abc/def/ghi = "FRED" then
  if root/abc/def/ghival != "" then
    output root/abc/def/ghival
  else
    output "0"
else
  output "0"

The inner IF is not a problem. Where the problem strikes is if the FRED
element does not exist. My current implementation (which doesn't work
properly, doesn't take account of this circumstance) goes like this:

<xsl:template match="abc">
  <xsl:for-each select="def">
    <xsl:if test="ghi='FRED'">
      <xsl:call-template name="OutputNotNull">
        <xsl:with-param name="value"
             select="def"/>
      </xsl:call-template>
    </xsl:if>
  </xsl:for-each>
</xsl:template>

(for clarity and brevity I've omitted the top-level templates and
OutputNotNull which simply outputs the value parameter, or 0 if it's empty.
Note also that I'm using strip-space elements="*" and output method="text"
indent="no")

I can't use an xsl:choose in place of the xsl:if because I need to examine
all of the elements in order to determine that FRED definitely does not
exist before writing out a 0.

FRED will exist once, and only once. Or not at all.

I'm hoping someone has some insight into this problem? It appears easy on
the surface, but I've found it intractable so far.

Many thanks in advance!

Best regards,
Curtis.


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


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.