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

RE: need to parse last 3 characters before .jpg

Subject: RE: need to parse last 3 characters before .jpg
From: "Mark Shellenberger" <mshellenberger@xxxxxxxxx>
Date: Fri, 12 Sep 2008 14:15:15 -0400
RE:  need to parse last 3 characters before .jpg
Geoff,

Let's see if I can offer a suggestion.  I bet you'll get a few.  First off
the example you provided wasn't well formed.  It required a closing items
tag.  Also the xsl:output/@method should be 'xhtml'.  

Right now you output all the images/image element values.  My impression
from your description is that you only wish to output one image element
value for each images element.  I also deduce this from the comment line in
the div/xsl:for-each select="images/image" that states - "need sqm image".
I'm not sure why you are trying to do string manipulation when you have an
attribute (image/@size) that corresponds to the value you are trying to pull
from the image/@src.

Using your current code I'd change the line:
<xsl:for-each select="images/image">

to

<xsl:for-each select="images/image[@size='_sqm']">

This change provides output of only the sqm jpg.  

It looks like you have other things to deal with in the code but I hope the
above helps.  Be sure to get back to me if I missed the point.

--Mark
XSLT Consultant
http://www.manorfieldconsulting.com
mark@xxxxxxxxxxxxxxxxxxxxxxxx

-----Original Message-----
From: Geoff Krajeski [mailto:GKrajeski@xxxxxxxxxxx] 
Sent: Friday, September 12, 2008 1:27 PM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject:  need to parse last 3 characters before .jpg

I'm trying to parse the last three characters to determine the image
size I need for a bunch of image nodes of varying sizes. I have the
following nodes and need to get the one with the sqm.jpg.  My xsl is
below.  Not sure where to go from here...


<feed>
	<contest>
		<title>Win a Commodore 128!</title>
	
<link>http://dev.taunton.com/contest/win-a-commodore-128</link>
		<items>
			<item>
				<images>
				<image size="_sqs"
src="http://dev.taunton.com/assets/uploads/posts/3529/quilt_full1_lg_sqs
.jpg" />
				<image size="_sqm"
src="http://dev.taunton.com/assets/uploads/posts/3529/quilt_full1_lg_sqm
.jpg" />
				<image size="_sql"
src="http://dev.taunton.com/assets/uploads/posts/3529/quilt_full1_lg_sql
.jpg" />
				<image size="_lg"
src="http://dev.taunton.com/assets/uploads/posts/3529/quilt_full1_lg_lg.
jpg" />
				<image size="_xl"
src="http://dev.taunton.com/assets/uploads/posts/3529/quilt_full1_lg_xl.
jpg" />
			  </images>
			  <title>vote for me you chump</title>
			  <member>phunkphuz7</member>
			  <date>Tue, 09 Sep 2008 22:07:30 -0400</date>

			  <description><![CDATA[seriously, it would mean
an awful lot to me.]]></description>
	
<link>http://dev.taunton.com/item/3529/vote-for-me-you-chump</link>
			</item>
			<item>
				<images>
				<image size="_sqs"
src="http://dev.taunton.com/assets/uploads/posts/3538/cs-v5-cat-sewing_s
qs.JPG" />
				<image size="_sqm"
src="http://dev.taunton.com/assets/uploads/posts/3538/cs-v5-cat-sewing_s
qm.JPG" />
				<image size="_sql"
src="http://dev.taunton.com/assets/uploads/posts/3538/cs-v5-cat-sewing_s
ql.JPG" />
				<image size="_lg"
src="http://dev.taunton.com/assets/uploads/posts/3538/cs-v5-cat-sewing_l
g.JPG" />
				<image size="_xl"
src="http://dev.taunton.com/assets/uploads/posts/3538/cs-v5-cat-sewing_x
l.JPG" />
			  </images>
			  <title>my entry</title>
			  <member>phunkphuz14</member>
			  <date>Tue, 09 Sep 2008 22:01:44 -0400</date>
			  <description><![CDATA[is this
working?]]></description>
	
<link>http://dev.taunton.com/item/3538/my-entry</link>
			</item>
	</contest>
</feed>

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0"
xmlns:html="http://www.w3.org/TR/REC-html40"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:contest="http://itsstagefuture.taunton.com/finewoodworking/usercon
trols/xsl">
<xsl:output method="html" version="1.0" encoding="iso-8859-1"
indent="yes"/>
  <!-- Root template -->    
  <xsl:template match="feed/contest">
    <html>     
      <head>  
        <title>Fine Woodworking - <xsl:value-of select="title" /> Most
Recent Posts</title>

		<style type="text/css">
			body { margin: 0; padding: 0; }
			.item { width: 189px; height: 289px; float:
left; background:
url(http://dev.taunton.com/assets/images/background_feed_contest_item.pn
g) 0 0 no-repeat; padding: 20px; }
		</style>
      </head>          

      <!-- Body -->
      <body>  
		<h1>Check out the most recent entries</h1>
		<a><xsl:attribute name="href"><xsl:value-of
select="link" /></xsl:attribute>View All Entries</a>
		<!-- Logo -->
		<xsl:for-each select="items/item">
			<div class="item">
				<xsl:for-each select="images/image">
					<!--<xsl:value-of select="@src"
/>-->
					<!-- need sqm image -->
					<xsl:value-of
select="substring-before(@src,'.jpg')" /><br/>
					<xsl:value-of
select="substring-after(@src,'_')" />
					<!--<xsl:value-of
select="string-length(substring-before(@src,'.jpg')" />-->
					  	<img><xsl:attribute
name="src"><xsl:value-of select="@src" /></xsl:attribute><xsl:attribute
name="alt"><xsl:value-of select="parent::node()/parent::node()/title"
/></xsl:attribute></img>
				</xsl:for-each>
				<a><xsl:attribute
name="href"><xsl:value-of select="link" /></xsl:attribute><xsl:value-of
select="title" /></a><br/>
			</div>
		</xsl:for-each>
      </body>

    </html>
  </xsl:template>
  <xsl:template match="image">
  	<img><xsl:attribute name="src"><xsl:value-of select="@src"
/></xsl:attribute></img>
  </xsl:template>

</xsl:stylesheet>

No virus found in this incoming message.
Checked by AVG - http://www.avg.com 
Version: 8.0.169 / Virus Database: 270.6.21/1668 - Release Date: 9/12/2008
6:56 AM

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

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