|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] 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: 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" xmlns:xs="http://www.w3.org/2001/XMLSchema" exclude-result-prefixes="xs" version="2.0"> <xsl:template match="@* | node()"> <xsl:copy> <xsl:apply-templates select="@*, node()"/> </xsl:copy> </xsl:template> <xsl:template match=" *[processing-instruction('Fm')[starts-with(., 'Condstart')]]"> <xsl:copy> <xsl:apply-templates select="@*"/> <xsl:for-each-group select="node()" group-starting-with=" processing-instruction('Fm')[starts-with(., 'Condstart')]"> <xsl:choose> <xsl:when test="self::processing-instruction('Fm')[starts-with(., 'Condstart')]"> <xsl:variable name="pi-start-name" as="xs:string" select="."/> <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:choose> <xsl:when test=" current-group()[last()][self::processing-instruction('Fm')[. = $pi-end-name]]"> <group name="{$pi-start-name}"> <xsl:apply-templates select="current-group()[position() ne last()]"/> </group> </xsl:when> <xsl:otherwise> <xsl:apply-templates select="current-group()"/> </xsl:otherwise> </xsl:choose> </xsl:for-each-group> </xsl:when> <xsl:otherwise> <xsl:apply-templates select="current-group()"/> </xsl:otherwise> </xsl:choose> </xsl:for-each-group> </xsl:copy> </xsl:template> </xsl:stylesheet> so that gives me <info> <group name="Condstart VbV-VCO"> <p>For this, use <b>that </b>to do that.</p> </group> <p><group name="Condstart USB">If you need this, do that.</group></p> <p>Outside paragraph.</p> </info>
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








