This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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@ntlworld.com
work: Michael.Kay@softwareag.com 


> 
> --nate
> 
> 
> --- Michael Kay <michael.h.kay@ntlworld.com> 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@ntlworld.com
> > work: Michael.Kay@softwareag.com
> > 
> > > -----Original Message-----
> > > From: owner-xsl-list@lists.mulberrytech.com
> > > [mailto:owner-xsl-list@lists.mulberrytech.com] On
> > Behalf Of
> > > Nathan Shaw
> > > Sent: 02 October 2002 18:18
> > > To: xsl-list@lists.mulberrytech.com
> > > Subject: Re: [xsl] 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@yahoo.com> 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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]