[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] finding next element after


Subject: Re: [xsl] finding next element after
From: Nathan Shaw <n8_shaw@xxxxxxxxx>
Date: Wed, 2 Oct 2002 10:18:24 -0700 (PDT)

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



Current Thread
Keywords
xml