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

RE: finding next element after

Subject: RE: finding next element after
From: "Michael Kay" <michael.h.kay@xxxxxxxxxxxx>
Date: Wed, 2 Oct 2002 20:09:39 +0100
RE:  finding next element after
> thanks Mike, that definitely makes it tighter. What
> about this line?
> 
> <xsl:value-of select="../../following-sibling::node()"
> />
> 
> Any cleaner way to write that? Seems dirty with the
> "../../" and the node() in there. All I want is to
> grab the Caption element's contents, which will always
> be text.

Well, I haven't looked at your problem in detail, but when I see lots of
"../..", I wonder if the code wouldn't be better written with a
different element as the context node.

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


> 
> --nate
> 
> 
> --- Michael Kay <michael.h.kay@xxxxxxxxxxxx> wrote:
> > You should replace this kind of test:
> > 
> >     <xsl:when test="local-name(parent::node())='p'">
> > 
> > with:
> > 
> >     <xsl:when test="parent::p">
> > 
> > Michael Kay
> > Software AG
> > home: Michael.H.Kay@xxxxxxxxxxxx
> > work: Michael.Kay@xxxxxxxxxxxxxx
> > 
> > > -----Original Message-----
> > > From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> > > [mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx] On
> > Behalf Of
> > > Nathan Shaw
> > > Sent: 02 October 2002 18:18
> > > To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> > > Subject: Re:  finding next element after
> > > 
> > > 
> > > I got it, but want to make sure that I am not
> > doing
> > > anything too funky here, as this is my first real
> > > foray into using axises.
> > > 
> > > <xsl:choose>
> > > 	<xsl:when
> > test="local-name(parent::node())='Link'">
> > > 		<xsl:if
> > >
> >
> test="local-name(../../following-sibling::node())='Caption'">
> > > 			<Caption>
> > > 				<xsl:attribute name="align">
> > > 						<xsl:value-of
> > > select="'bottom'" />
> > > 						</xsl:attribute>
> > > 						<xsl:value-of
> > > select="../../following-sibling::node()" />
> > > 					</Caption>
> > > 				</xsl:if>
> > > 			</xsl:when>
> > > 			<xsl:when
> > test="local-name(parent::node())='p'">
> > > 				<xsl:if
> > >
> >
> test="local-name(../following-sibling::node())='Caption'">
> > > 					<Caption>
> > > 						<xsl:attribute
> > > name="align">
> > > 								
> > > <xsl:value-of select="'bottom'" />
> > > 						</xsl:attribute>
> > > 						<xsl:value-of
> > > select="../following-sibling::node()" />
> > > 					</Caption>
> > > 				</xsl:if>
> > > 			</xsl:when>
> > > 			<xsl:otherwise></xsl:otherwise>
> > > 		</xsl:choose>
> > > 
> > > Thoughts? Is there an easier/better way to
> > accomplish
> > > this?
> > > 
> > > --nate
> > > 
> > > 
> > > --- Nathan Shaw <n8_shaw@xxxxxxxxx> wrote:
> > > > Here is my deal. I am trying to associate a
> > caption
> > > > with an image. The XML I am parsing will always
> > look
> > > > like this:
> > > > 
> > > > With a caption and a link:
> > > > <p><Link href="http://islswg.hq.nasa.gov/"><img
> > > > src="C:\Documents and Settings\nshaw.HQIRMS\My
> > > > Documents\genericpics\ISS\transhub.jpg"
> > > > height="120.75" width="156.75"/></Link></p>
> > > > <Caption>Picture of the ISS TransHAB.</Caption>
> > > > 
> > > > OR
> > > > 
> > > > With a caption and no link:
> > > > <p><img src="C:\Documents and
> > > > Settings\nshaw.HQIRMS\My
> > Documents\genericpics\ISS\transhub.jpg"
> > > > height="120.75" width="156.75"/></p>
> > > > <Caption>Picture of the ISS TransHAB.</Caption>
> > > > 
> > > > OR
> > > > With a link and no caption:
> > > > <p><Link href="http://islswg.hq.nasa.gov/"><img
> > > > src="C:\Documents and Settings\nshaw.HQIRMS\My 
> > > > Documents\genericpics\ISS\transhub.jpg"
> > > > height="120.75" width="156.75"/></Link></p>
> > > > 
> > > > OR
> > > > 
> > > > With no link or caption:
> > > > <p><img src="C:\Documents and
> > > > Settings\nshaw.HQIRMS\My
> > Documents\genericpics\ISS\transhub.jpg"
> > > > height="120.75" width="156.75"/></p>
> > > > 
> > > > I want my resulting ouput to look like this (of
> > > > course
> > > > there would not be a Link or Caption element if
> > > > those
> > > > did not exist in the original XML):
> > > > 
> > > > <Media type="image" id="transhub"
> > > > file="http://www.nasa.gov/images/aero.gif"
> > > > width="157"
> > > > height="121" border="" alt="Picture of the ISS
> > > > TransHAB." align="left"><Link
> > url="http://islswg.hq.nasa.gov/"
> > > > type="internal"/><Caption align="bottom">Picture
> > of
> > > > the ISS TransHAB.</Caption>
> > > > </Media>
> > > > This is as close as I have gotten in my XSLT.
> > > > Finding
> > > > the next following Caption element is tripping
> > me up
> > > > ((following-sibling::*[1])[self::Caption])!
> > > > 
> > > > <xsl:template match="img">
> > > > 	<Media>
> > > > 		<xsl:attribute name="type">
> > > > 				<xsl:value-of 
> select="'image'" />
> > > > 		</xsl:attribute>
> > > > 		<xsl:variable name="fileName">
> > > > 			<xsl:call-template name="getFileName">
> > > > 				<xsl:with-param name="FilePath"
> > > select="@src" />
> > > > 			</xsl:call-template>
> > > > 		</xsl:variable>
> > > > 		<xsl:variable name="imgID"
> > > select="substring-before($fileName,'.')"
> > > > />
> > > > 		<xsl:attribute name="id">
> > > > 				<xsl:value-of select="$imgID" />
> > > > 		</xsl:attribute>
> > > > 		<xsl:attribute name="file">
> > > > 			<xsl:value-of
> > > >
> > >
> >
> select="concat('http://www.nasa.gov/images/',$fileName)"
> > > > />
> > > > 		</xsl:attribute>
> > > > 		<xsl:attribute name="width">
> > > > 				<xsl:value-of 
> select="round(@width)" />
> > > > 		</xsl:attribute>
> > > > 		<xsl:attribute name="height">
> > > > 				<xsl:value-of 
> select="round(@height)" />
> > > > 		</xsl:attribute>
> > > > 		<xsl:attribute name="border">
> > > > 				<xsl:value-of 
> select="@border" />
> > > > 		</xsl:attribute>
> > > > 		<xsl:attribute name="alt">
> > > > 				<xsl:value-of
> > > select="/NewsRelease/Body/caption"
> > > > />
> > > > 		</xsl:attribute>
> > > > 		<xsl:if
> > test="local-name(parent::node())='Link'">
> > > > 			<Link>
> > > > 				<xsl:attribute name="url">
> > > > 						<xsl:value-of
> > > select="../@href" />
> > > > 				</xsl:attribute>
> > > > 				<xsl:variable name="nasaURL">
> > > > 					
> <xsl:call-template name="LCase">
> > > > 						<xsl:with-param
> > > name="string"
> > > > select="../@href"
> > > > />
> > > > 					</xsl:call-template>
> > > > 				</xsl:variable>
> > > > 				<xsl:attribute name="type">
> > > > 					<xsl:choose>
> > > > 						<xsl:when
> > > > test="contains($nasaURL,'nasa.gov')">
> > > > 							
> > > <xsl:value-of select="'internal'" />
> > > > 						</xsl:when>
> > > > 						<xsl:otherwise>
> > > > 							
> > > <xsl:value-of select="'external'" />
> > > > 						</xsl:otherwise>
> > > > 					</xsl:choose>
> > > > 				</xsl:attribute>
> > > > 			</Link>
> > > > 		</xsl:if>
> > > > 		<xsl:if 
> test="(following-sibling::*[1])[self::Caption]">
> > > > 			<Caption>
> > > > 				<xsl:attribute name="align">
> > > > 						<xsl:value-of 
> > > select="'bottom'" />
> > > > 				</xsl:attribute>
> > > > 				<xsl:value-of
> > > select="(following-sibling::*[1])[self::Caption]"
> > />
> > > > 			</Caption>
> > > > 		</xsl:if>
> > > > 	</Media>
> > > > </xsl:template>
> > > > 
> > > > thanks in advance for the help! I have been
> > racking
> > > > me
> > > > brain for hours and hours on this!
> > > > 
> > > > --nate
> > > > 
> > > >
> > __________________________________________________
> > > > Do you Yahoo!?
> > > > New DSL Internet Access from SBC & Yahoo!
> > http://sbc.yahoo.com
> > > > 
> > > >  XSL-List info and archive: 
> > > > http://www.mulberrytech.com/xsl/xsl-list
> > > > 
> > > 
> > > 
> > > __________________________________________________
> > > Do you Yahoo!?
> > > New DSL Internet Access from SBC & Yahoo! http://sbc.yahoo.com
> > > 
> > >  XSL-List info and archive:
> > http://www.mulberrytech.com/xsl/xsl-list
> > > 
> > 
> > 
> >  XSL-List info and archive:
> > http://www.mulberrytech.com/xsl/xsl-list
> > 
> 
> 
> __________________________________________________
> Do you Yahoo!?
> New DSL Internet Access from SBC & Yahoo!
> http://sbc.yahoo.com
> 
>  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

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.