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

Re: General algorithm for finding nodes between PIs

Subject: Re: General algorithm for finding nodes between PIs
From: "Rick Quatro rick@xxxxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Fri, 27 Jan 2017 15:13:11 -0000
Re:  General algorithm for finding nodes between PIs
Hi Martin,

That is fantastic, thank you very much! As you can see from my immediately
preceding email, I need something a little different. But with your solution
(which answered the original question), I can run a second pass to get what
I need (as stated in the last email). Thank you again for your generosity.


-----Original Message-----
From: Martin Honnen martin.honnen@xxxxxx
Sent: Friday, January 27, 2017 9:58 AM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: Re:  General algorithm for finding nodes between PIs

On 27.01.2017 15:24, Rick Quatro rick@xxxxxxxxxxxxxx wrote:
> I modified my input document slightly:
> <?xml version="1.0" encoding="UTF-8"?> <info>
>     <?Fm Condstart VbV-VCO?>
>     <p>For this, use <b>that </b>to do that.</p>
>     <?Fm Condend VbV-VCO?>
>     <p><?Fm Condstart USB?>If you need this, do that.<?Fm Condend
>     <p>Outside paragraph.</p>
> </info>

> This is close, but I don't want to lose any elements from the output, 
> like the parents of the processing instructions (<info>, <p>). Also, I 
> am not picking up my last <p> element. Thank you for the generous help.

Here is an adaption that tries to keep all data and simply replaces any
pi(star/end) pair with a wrapper 'group' element:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
exclude-result-prefixes="xs" version="2.0">

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

	<xsl:template match="
			<xsl:apply-templates select="@*"/>
			<xsl:for-each-group select="node()"
name="pi-start-name" as="xs:string" select="."/>
name="pi-end-name" select="replace(., 'Condstart', 'Condend')"/>
select="current-group() except ."
group-ending-with="processing-instruction('Fm')[. = $pi-end-name]">
current-group()[last()][self::processing-instruction('Fm')[. =
<group name="{$pi-start-name}">
select="current-group()[position() ne last()]"/>
<xsl:apply-templates select="current-group()"/>


so that gives me

	<group name="Condstart VbV-VCO">
	<p>For this, use <b>that </b>to do that.</p>
	<p><group name="Condstart USB">If you need this, do
	<p>Outside paragraph.</p>

Current Thread


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.
First Name
Last Name
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.