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

RE: [xsl] Getting all the values between empty elements


Subject: RE: [xsl] Getting all the values between empty elements
From: "Michael Kay" <mhk@xxxxxxxxx>
Date: Mon, 5 Jan 2004 21:06:25 -0000

> I have one final XPath-related question.

Optimist!
> 
> If I have a series of sibling elements like <a/>, below:
> 
> <p>
> 	<a/>One or two <b>items</b><a/>or <i>another</i>, I 
> dare say<a/><c val="#0f0">a third</c>, do you think?<br/> </p>
> 
> how can I get at "everything between one a and the next a"?

If the <a> elements are always at the same (top) level, this isn't too
difficult. If they can be at any depth, it gets tough, though there are
solutions in the archive of the list.

You can do something along the lines of

<xsl:for-each select="a">
  <xsl:variable name="next"
select="generate-id(following-sibling::a[1])"/>
  <xsl:apply-templates select="following::sibling::node()
    [generate-id(following-sibling::a[1]) != $next or $next='']"/>

Michael Kay

> 
> Right now, I am formatting by matching on <br/> and looping 
> backwards (this is greatly simplified).
> 
> <xsl:template match="br">
> 
> 	<xsl:for-each select="preceding-sibling::a">
> 
> 		<xsl:value-of select="preceding-sibling::text()[1]"/>	
> 								
> 	</xsl:for-each>
> 			
> </xsl:template>	
> 
> But, of course, I've run into the problem that what is 
> in-between <a/>s, could contain elements that would call for 
> further application of templates - it might not be text-alone.
> 
> This is my last question on this particular problem.  Thank 
> you very much, everyone who has helped me thus far. I hope 
> eventually I will progress to a point where I can say 
> something that is of help to someone else.
> 
> KP
> 
> 
>  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