[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 14:57:22 -0000
Re:  General algorithm for finding nodes between PIs
Thanks for the reply. What I really want is this:

Input:

<?xml version="1.0" encoding="UTF-8"?>
<info>
    <?Fm Condstart VbV-VCO?>
    <p>For this, use <b>that </b>to do that.</p>
    <p>Another paragraph</p>
    <?Fm Condend VbV-VCO?>
    <p><?Fm Condstart USB?>If you need this, do that.<?Fm Condend USB?></p>
    <p>Outside paragraph.</p>
</info>

Output:

<?xml version="1.0" encoding="UTF-8"?>
<info>
    <p platform="VbV-VCO">For this, use <b>that </b>to do that.</p>
    <p platform="VbV-VCO">Another paragraph</p>
    <p platform="USB">If you need this, do that.</p>
    <p>Outside paragraph.</p>
</info>

The basic logic is this: given a "Condstart" processing instruction:

* If the first sibling is an element, then assign an attribute to all
following sibling elements up to the corresponding Condend processing
instruction.

* If the first sibling is a text node, then assign an attribute to the
parent of the Condstart processing instruction.

I didn't phrase my question like this the first time because I wanted to
approach it in stages to try to understand how a solution would work. I
don't want to say "I have this" and "need that" and just copy/paste a
solution. I really want to understand what is happening in my style sheet.
Thanks for your generous help.

Rick

-----Original Message-----
From: Martin Honnen martin.honnen@xxxxxx
[mailto:xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx] 
Sent: Friday, January 27, 2017 9:42 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
USB?></p>
>     <p>Outside paragraph.</p>
> </info>
>
> Here is how I have implemented Michael's stylesheet:
>
> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>  	xmlns:xs="http://www.w3.org/2001/XMLSchema"
>  	exclude-result-prefixes="xs"
>  	version="2.0">
>  	
>  	<xsl:output indent="yes"/>
>
>  	<xsl:template match="/">
>  		<results>
>  			<xsl:apply-templates/>
>  		</results>
>  	</xsl:template>
>  	
>  	<xsl:template match="*[processing-instruction('Fm')[starts-with(.,
> 'Condstart')]]">
>  		<xsl:for-each-group select="node()"
> group-starting-with="processing-instruction('Fm')[starts-with(.,
> 'Condstart')]">
>  			<xsl:if
> test="self::processing-instruction('Fm')[starts-with(., 'Condstart')]">
>  				<group name="{.}">
>  					<xsl:variable name="pi-end-name"
> select="replace(., 'Condstart', 'Condend')"/>
>  					<xsl:for-each-group
> select="current-group() except ."
> group-ending-with="processing-instruction('Fm')[. = $pi-end-name]">
>  						<xsl:if
> test="current-group()[last()][self::processing-instruction('Fm')[. = 
> $pi-end-name]]">
>  							<xsl:copy-of
> select="current-group()[position() ne last()]"/>
>  						</xsl:if>
>  					</xsl:for-each-group>
>  				</group>
>  			</xsl:if>
>  		</xsl:for-each-group>
>  		<xsl:apply-templates/>
>  	</xsl:template>
>  	
>  	<xsl:template match="text()"/>
>  	
> </xsl:stylesheet>
>
> Here is my output:
>
> <?xml version="1.0" encoding="UTF-8"?> <results>
>    <group name="Condstart VbV-VCO">
>       <p>For this, use <b>that </b>to do that.</p>
>     </group>
>    <group name="Condstart USB">If you need this, do that.</group> 
> </results>
>
> 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.

So which output do you want for that input sample? Do you want to generate
two documents, one containing the groups for the processing instructions,
the other copying the input, or do you want to mix the input with the
groups? In the last case, how exactly?

I am sure we can adapt the code once we know exactly which result you want,
but currently I am not sure how that result is supposed to look like.

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.