Subject: Re: [xsl] grouping of processing instruction From: "Dimitre Novatchev dnovatchev@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> Date: Fri, 26 Sep 2014 05:41:58 -0000 |
On Thu, Sep 25, 2014 at 9:51 PM, Joga Singh Rawat jrawat@xxxxxxxxxxxxxx <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote: > <?xml-start?>anything including tags<?xml-end?> Something like this: <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output omit-xml-declaration="yes" indent="yes"/> <xsl:template match="/"> <xsl:for-each-group select= "(following::processing-instruction() | descendant::processing-instruction() )[name()='pi-start']" group-starting-with="processing-instruction()[name()='pi-start']"> ========== Start ============== <xsl:variable name="thePI" select="."/> <xsl:sequence select= "$thePI/following-sibling::node() [$thePI/following::processing-instruction() [name()='pi-end'][1] >> .] "/> ========== End ============== </xsl:for-each-group> </xsl:template> </xsl:stylesheet> When this transformation is applied on the following source XML document: <x p="q" r="t"> <m/> <?pi-start ?> <y>1</y>a <z>3</z>b <y>2</y> <a><b/></a> <c><d>5 <?pi-end ?> </d> </c> <g><h>8</h>9</g> </x> the wanted, correct result is produced: ========== Start ============== <y>1</y>a <z>3</z>b <y>2</y> <a> <b/> </a> <c> <d>5 <?pi-end ?> </d> </c> ========== End ============== (Of course, the start/end string delimiters above can be substituted with whatever is wanted in your particular case). Also, note that an element cannot be cut into a start-tag and end-tag, and some quite special tricks (hand-written, special serialization) need to be performed if you really want the trailing end tags (following <pi-end>) to be removed. In this case, one must specify that the type of the output is text (not xml). In case the "end" PI is not wanted in the output, one way to remove this is to capture the output above in a variable and run a second-pass on this variable, which will remove the "end" PI (simply by overriding the identity template). -- Cheers, Dimitre Novatchev --------------------------------------- Truly great madness cannot be achieved without significant intelligence. --------------------------------------- To invent, you need a good imagination and a pile of junk ------------------------------------- Never fight an inanimate object ------------------------------------- To avoid situations in which you might make mistakes may be the biggest mistake of all ------------------------------------ Quality means doing it right when no one is looking. ------------------------------------- You've achieved success in your field when you don't know whether what you're doing is work or play ------------------------------------- To achieve the impossible dream, try going to sleep. ------------------------------------- Facts do not cease to exist because they are ignored. ------------------------------------- Typing monkeys will write all Shakespeare's works in 200yrs.Will they write all patents, too? :) ------------------------------------- I finally figured out the only reason to be alive is to enjoy it.
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] grouping of processing instru, Joga Singh Rawat jra | Thread | Re: [xsl] grouping of processing in, Dimitre Novatchev dn |
[xsl] grouping of processing instru, Joga Singh Rawat jra | Date | Re: [xsl] grouping of processing in, Dimitre Novatchev dn |
Month |