[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: Mukul Gandhi <gandhi.mukul@xxxxxxxxx>
Date: Fri, 6 May 2011 15:12:38 +0530
Re:  block selection question (XSLT 1.0)
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@xxxxxxxxxx> wrote:
> Hello,
>
> I know that this is basic but I cannot get it done correctly.
>
> Input:
> <lines>
> B <line></line>
> B <line>A1</line>
> B <line>1</line>
> B <line>B1</line>
> B <line></line>
> B <line>A2</line>
> B <line>2</line>
> B <line>2</line>
> B <line>2</line>
> B <line>B2</line>
> B <line></line>
> B <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
> B  B <xsl:for-each select="/lines/line[contains(.,'A')]">
> B  B  B <xsl:copy-of select="."/>
> B  B </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"
> B xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>>
> B <xsl:output omit-xml-declaration="yes"/>
>
> B <xsl:template match="/">
> B  B <xsl:for-each select="/lines/line[contains(.,'A')]">
> B  B  B <xsl:copy-of select="."/>
> B  B  B <xsl:copy-of select="following-sibling::*[not(contains(.,'B'))]"/>
> B  B </xsl:for-each>
> B </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

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.