Re: [xsl] Conditional processing for first and last of a set of elements

Subject: Re: [xsl] Conditional processing for first and last of a set of elements
From: David Carlisle <davidc@xxxxxxxxx>
Date: Wed, 10 Mar 2004 12:19:41 GMT
You are thinking in terms of writing out markup tags, not of generating
a tree of nodes. XSLT can be used for this but you would be much better
to use a text editing system such a s sed or perl if you need to think
of XML at that level.

In particular, if you are using  disable-output-escaping then there is
almost always something very wrong with your stylesheet.

Assuming that your br are all siblings of each other then what you want
to do is first process everything before the first br

<xsl:copy-of select="br[1]/preceding-sibling:node()"/>

Then
make a table
<table>
 grabbing each set of nodes between br elements and putting them in a row
<xsl:for-each select="br[position()&lt;last()">
 <tr><td>
  <xsl:copy-of select="following-sibling::node()[generate-id(current())=generate-id(preceding-sibling::br[1])]"/>
 </td></tr>
</xsl:for-each>
</table>

now handle the final stuff

<xsl:copy-of select="br[last()]/following-sibling:node()"/>


Note in the above I used a n Xpath of btr to reasch a br node as that as
what you used, but if your input is xhtml as you said it will be in teh
xhtml namespace in which case your xpath will need to be h:br where h is
bound to the xhtml namespace.


Other things:
   match="//br
Never start a match with // (it does not do anything useful)

  "position()=//br[text()='LineNumberHolder']
this is comparing position() (which is a number) with the string value
of a br element, which is the character data of br, but br is an empty
element so its string value is "" as the number coerced to a string will
never be empty this test will never be true.

  disable-output-escaping="yes"

As i said above never use that while generating xml, it is useful for
generating "almost" xml formats like the <%.. syntax used in some
template scripting languages.

David


  

-- 
http://www.dcarlisle.demon.co.uk/matthew

________________________________________________________________________
This e-mail has been scanned for all viruses by Star Internet. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread