This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Tricky one
- From: "Curtis Burisch" <curtis at london dot com>
- To: <xsl-list at lists dot mulberrytech dot com>
- Date: Thu, 22 Aug 2002 13:53:23 +0100
- Subject: [xsl] Tricky one
- Reply-to: xsl-list at lists dot mulberrytech dot com
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