[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
RE: [xsl] finding next element after
Subject: RE: [xsl] finding next element after From: "Michael Kay" <michael.h.kay@xxxxxxxxxxxx> Date: Wed, 2 Oct 2002 20:09:39 +0100 |
> 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: [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@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 |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] finding next element afte, Nathan Shaw | Thread | RE: [xsl] finding next element afte, Nathan Shaw |
[xsl] Prob using xsl namespace acro, ALFANO, ALAN (SNETCO | Date | RE: [xsl] Prob using xsl namespace , Michael Kay |
Month |
Keywords