This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RE: Tricky one


Hi Curtis
if i understand it right, you want to display <ghival> if there is at
least one <ghi>=Fred and 0 if there is none?

If that is the case then you can do something like

 <xsl:template match="abc">
  <xsl:choose>
   <xsl:when test="def/ghi='FRED'"> <!-- tests if there is at least one
ghi='FRED' -->
   <xsl:choose>
    <xsl:when test="not(def[ghi='FRED']/ghival='')">
    <xsl:value-of select="def[ghi='FRED']/ghival"/>
    <!-- here you can change de <xsl:value-of...> by:
    <xsl:call-template name="OutputNotNull">
     <xsl:with-param name="value" select="def[ghi='FRED']"/>
    </xsl:call-template>
    -->
    </xsl:when>
    <xsl:otherwise> 0
    </xsl:otherwise>
   </xsl:choose>
   </xsl:when>
   <xsl:otherwise> 0
   </xsl:otherwise>
  </xsl:choose>
 </xsl:template>

-----Original Message-----
From: owner-xsl-list@lists.mulberrytech.com
[mailto:owner-xsl-list@lists.mulberrytech.com] On Behalf Of Curtis
Burisch
Sent: Thursday, August 22, 2002 1:53 PM
To: xsl-list@lists.mulberrytech.com
Subject: [xsl] 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



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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]