[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: block selection question (XSLT 1.0)

Subject: Re: block selection question (XSLT 1.0)
From: Martin Honnen <Martin.Honnen@xxxxxx>
Date: Fri, 06 May 2011 11:44:49 +0200
Re:  block selection question (XSLT 1.0)
Hermann Stamm-Wilbrandt wrote:

I know that this is basic but I cannot get it done correctly.

Input:
<lines>
   <line></line>
   <line>A1</line>
   <line>1</line>
   <line>B1</line>
   <line></line>
   <line>A2</line>
   <line>2</line>
   <line>2</line>
   <line>2</line>
   <line>B2</line>
   <line></line>
   <line></line>
</lines>

Intended output (blockwise, start at A, all including next B):
<line>A1</line>
<line>1</line>

<line>A2</line>
<line>2</line>
<line>2</line>
<line>2</line>


The following stylesheet outputs the above result:

<xsl:stylesheet
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  version="1.0">

<xsl:output indent="yes"/>

<xsl:key name="k1"
match="line[not(starts-with(., 'A')) and not(starts-with(. , 'B')) and node()]"
use="generate-id(preceding-sibling::line[starts-with(., 'A')][1])"/>


  <xsl:template match="@* | node()" name="identity">
    <xsl:copy>
      <xsl:apply-templates select="@* | node()"/>
    </xsl:copy>
  </xsl:template>

  <xsl:template match="lines">
    <xsl:apply-templates select="line[starts-with(., 'A')]"/>
  </xsl:template>

  <xsl:template match="line[starts-with(., 'A')]">
    <xsl:call-template name="identity"/>
    <xsl:apply-templates select="key('k1', generate-id())"/>
  </xsl:template>

</xsl:stylesheet>

I am however not sure whether the condition used
  "and node()"
is what you want.


--


	Martin Honnen
	http://msmvps.com/blogs/martin_honnen/

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.