[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] 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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|