[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] grouping of processing instruction

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=
      | descendant::processing-instruction()

   ========== Start ==============
   <xsl:variable name="thePI" select="."/>
   <xsl:sequence select=
                >> .]
   ========== End ==============

When this transformation is applied on the following source XML document:

<x p="q" r="t">
  <?pi-start ?>
 <c><d>5  <?pi-end ?>

the wanted, correct result is produced:

   ========== Start ==============

   <d>5  <?pi-end ?>
   ========== 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).

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