This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [XSL] Controlling Output Based on XML Processing Instructions


Matthew,

This can be done, but....

At 04:30 PM 1/18/02, you wrote:
>Dear fellow list members;
>
>Question: Is it possible to use XML processing instructions from the 
>source XML document to control what is included in the output tree?
>
>Example:
><xmlRoot>
>   <parent>
>     <child1/>
>     <?insertStart?>
>     <child2/>
>     <?insertEnd?>
>     <?deleteStart?>
>     <child3/>
>   </parent>
></xmlRoot>
>
>Now, since XML processing instructions are not considered part of the XML 
>node hierarchy,

Actually they are, unless you mean by "node hierarchy" that the processor 
ought to know that you mean the characters "insertStart" to "start" 
something, and "insertEnd" to stop something (the same something), etc. In 
other words, they can't perform the function that is so natural for 
elements, wrapping something up.

>  is it possible to use them in XSL to control things such as whether 
> anything between the <?insertStart?> and <?insertEnd?> is included in the 
> XSL output and anything between the <?deleteStart?> and <?deleteEnd?> is 
> not included in the output?

Yes, it is, but it's fairly painful. A simple SAX or SAX-like filter in the 
language of your choice would be a far easier and more natural way to do this.

>I know that it is possible to use the processing-instruction() function to 
>get the name and text values of the content, but it seems that it would be 
>difficult to use this to control the output.

In principle, yes. You'd have to worry about parsing the content of the PI 
in XSLT (fairly painful), then instituting its logic, which as I suggested 
would have to make up for the fact that the "start/end" semantics of your 
PI pairings aren't built in.

If you don't want to solve the problem in a serial filter that works 
directly over the data stream, a simpler pre-process (Perl, sed, what have 
you) that would change the PIs into honest element start- and end-tags 
would give you element containment, would make the job way way easier in XSLT.

>  Has anyone done anything like this before?

I'm beginning to think someone's tried just about everything in XSLT in its 
short life. But I wouldn't recommend doing this. It's be a classic case of 
the golden hammer used to tighten a nut.

Cheers,
Wendell



======================================================================
Wendell Piez                            mailto:wapiez@mulberrytech.com
Mulberry Technologies, Inc.                http://www.mulberrytech.com
17 West Jefferson Street                    Direct Phone: 301/315-9635
Suite 207                                          Phone: 301/315-9631
Rockville, MD  20850                                 Fax: 301/315-8285
----------------------------------------------------------------------
   Mulberry Technologies: A Consultancy Specializing in SGML and XML
======================================================================


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]