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

RE: replacing images with alt tags

Subject: RE: replacing images with alt tags
From: "Michael Kay" <michael.h.kay@xxxxxxxxxxxx>
Date: Thu, 18 Apr 2002 10:13:12 +0100
xsl alt image
> I am trying to remove images when converting from xhtml to
> wml.  I want
> to replace them with their alt tags.  Below is my xslt.  I want to
> handle different cases such that if the image is the link for
> an anchor
> tag it is replaced with the alt text, if it is within a <p>
> tag then it
> places the alt tag in its place, and last if it is not within
> either of
> the above then it places the alt tag within its own <p> tags.  What I
> have below is not working.  The only part that works is the otherwise
> part.  Is there something wrong with my choose?  How can I do this
> better?  And how can I get the alt text to replace the
> ||image skipped||
> that I currently have?  And better yet is their a good way to do away
> with this and convert images?  That's probably wishful thinking :)
> <xsl:template match="img">
> 	<xsl:choose>
> 	<xsl:when test="parent::a">	<!--img presents the src for an
> image if the image is a link ie. has parent::a-->
> 		 <xsl:copy-of select="@alt"/>
>  	</xsl:when>
> 	<xsl:when test="parent::p">
> 	   	  (image - <xsl:copy-of select="@alt"/>)
>     	</xsl:when>
> 	<xsl:otherwise>
> 	    	<p>
> 	    	||image skipped||
> 	   	</p>
> 	</xsl:otherwise>
> 	</xsl:choose>
> </xsl:template>
My first reaction on seeing this kind of template rule is to break it up:

 <xsl:template match="a/img">
   <xsl:value-of select="@alt"/> <!-- ? -->

 <xsl:template match="p/img">
   <xsl:value-of select="@alt"/> <!-- ? -->

 <xsl:template match="img">
   <p><xsl:value-of select="@alt"/></p>

I don't know if this is exactly the output you wanted, your description
implied some difference between the a/img and p/img cases but I can't quite
see what the difference is.

Michael Kay
Software AG
home: Michael.H.Kay@xxxxxxxxxxxx
work: Michael.Kay@xxxxxxxxxxxxxx

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

Current Thread


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.
First Name
Last Name
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.