Subject: RE: [xsl] Conditional branching on string attribute in IE5? From: "Steve Gold" <Steve@xxxxxxxxxxxxx> Date: Sun, 29 Dec 2002 23:12:07 -0500 |
Try moving the "contains" inside square brackets [] Below is XSL and XML that does what you want. (I changed to xsl:choose from xsl:if because you said you'd have other cases to check aside from images.) It works if you do the following XSL: <?xml version="1.0"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:template match="/"> <xsl:for-each select="xml/info"> <xsl:choose> <xsl:when test="@path[contains(.,'.jpg') or contains(.,'gif')]"> Image: <xsl:value-of select="@path" /><br /> </xsl:when> <xsl:when test="@path[contains(.,'.htm') or contains(.,'html')]"> Href: <xsl:value-of select="@path" /><br /> </xsl:when> </xsl:choose> </xsl:for-each> </xsl:template> </xsl:stylesheet> Here is the XML I used: <?xml version="1.0"?> <?xml-stylesheet type="text/xsl" href="contains.xsl"?> <xml> <info path="abc.txt" /> <info path="def.gif" /> <info path="ghi.jpg" /> <info path="jkl.xml" /> <info path="mno.htm" /> </xml> This is the output: Image: def.gif Image: ghi.jpg Href: mno.htm Enjoy, Steve -----Original Message----- From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx [mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of drsystems@xxxxxxxx Sent: Sunday, December 29, 2002 10:14 PM To: XSL-List@xxxxxxxxxxxxxxxxxxxxxx Subject: [xsl] Conditional branching on string attribute in IE5? Hi, This is for IE5. For an XML file like: <xml> <info path="abc.txt"> <info path="abc.jpg"> </xml> I want to check the value of xml/info/path, and if it contains a .jpg or .gif extension, generate an img node, else generate an href node. I tried the following: .. <xsl:for-each select="xml/info"> <xsl-if test="contains(@path,'.jpg')"> <xsl-element name="a"> .. and got an error, "Unknown method contains(@". What is the right way to do this for IE5? Upgrade to IE6 is not an option :-( This is urgent, and I am stuck at this. Please help out a new XSL enthusiast! :) Thanks, XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] Conditional branching on stri, drsystems | Thread | Re: [xsl] Conditional branching on , Joerg Heinicke |
[xsl] Conditional branching on stri, drsystems | Date | Re: [xsl] regarding unique nodes in, Joerg Heinicke |
Month |