This looks like a sibling recursion problem.
The following seems to work.
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml" indent="yes" />
<xsl:template match="lines">
<result>
<xsl:apply-templates select="line[contains(., 'A')]"/>
</result>
</xsl:template>
<xsl:template match="line">
<xsl:if test="not(contains(., 'B'))">
<xsl:copy-of select="."/>
<xsl:apply-templates select="following-sibling::*[1]"/>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
On Fri, May 6, 2011 at 2:43 PM, Hermann Stamm-Wilbrandt
<STAMMW(_at_)de(_dot_)ibm(_dot_)com> wrote:
Hello,
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>
This
<xsl:for-each select="/lines/line[contains(.,'A')]">
<xsl:copy-of select="."/>
</xsl:for-each>
gives
<line>A1</line>
<line>A2</line>
And this output is too much (double output of 2nd block)
$ xsltproc y.xsl lines.xml | tidy -q -xml
<line>A1</line>
<line>1</line>
<line />
<line>A2</line>
<line>2</line>
<line>2</line>
<line>2</line>
<line />
<line />
<line>A2</line>
<line>2</line>
<line>2</line>
<line>2</line>
<line />
<line />
$ cat y.xsl
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
<xsl:output omit-xml-declaration="yes"/>
<xsl:template match="/">
<xsl:for-each select="/lines/line[contains(.,'A')]">
<xsl:copy-of select="."/>
<xsl:copy-of select="following-sibling::*[not(contains(.,'B'))]"/>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
$
I tried making use of "preceding-sibling::*" at different places without
success sofar.
Any help is appreciated.
Mit besten Gruessen / Best wishes,
Hermann Stamm-Wilbrandt
Developer, XML Compiler, L3
Fixpack team lead
WebSphere DataPower SOA Appliances
https://www.ibm.com/developerworks/mydeveloperworks/blogs/HermannSW/
----------------------------------------------------------------------
IBM Deutschland Research & Development GmbH
Vorsitzender des Aufsichtsrats: Martin Jetter
Geschaeftsfuehrung: Dirk Wittkopp
Sitz der Gesellschaft: Boeblingen
Registergericht: Amtsgericht Stuttgart, HRB 243294
--
Regards,
Mukul Gandhi
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--