[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: processing-instruction()

Subject: Re: processing-instruction()
From: Dimitre Novatchev <dnovatchev@xxxxxxxxx>
Date: Wed, 31 Jul 2002 08:04:41 -0700 (PDT)
match processing instruction
--- "Jiang, Peiyun" <Peiyun dot Jiang at nrc dot ca> wrote:
 
> What's wrong?
> 
> I'm trying to match processing instructions. I want to get rid of the
> <?Eqn
> TeX input="\hskip -32pt\hbox to32pt{[6]}"?> part in the source file. 
> 
> Source file: <equation> and <inlineequation> mixed with text and
> markup.
> XSLT: I match every <equation> and <inlineequation> and copy
> recursively any
> attributes and elements. I match processing instructions and remove
> them all
> (but I want to keep some of them later).
> output: no processing instructions removed.
> 
> Am I doing the right thing to match the processing instructions? See
> stylesheet below.
> 
> Thanks.
> 
> Peiyun
> 
> 
> -----------------------
> source: equations mixed with text.
> <doc>Text before equations.
> <inlineequation id="il1"><?Pub Eqn?>
> <f><rm><a><ac>CV</ac><ac>&d4;</ac></a><fen lp="par"><rm><g>q</g></rm>
> <rp post="par"/></fen></rm></f>
> </inlineequation>
> More text and other <tags></tags> more text.
> <equation id="eqn006"><?Pub Eqn?>
> <fd><fl><rm><?Eqn TeX input="\hskip -32pt\hbox to32pt{[6]}"?></rm>
> <rm>Prob<fen
> lp="par"><mit>m<inf>ij</inf>&vbm0;R<inf>j</inf><rm>,</rm>
> <g>p</g><inf>ij</inf></mit><rp post="par"/></fen>=<fen lp="par"><stk>
>
<lyr><mit>Rj</mit></lyr><lyr><it><mit>m<inf>ij</inf></mit></it></lyr></stk>
> <rp
> post="par"/></fen><g>p</g><sup><mit>m<inf>ij</inf></mit></sup><inf>
> <mit>ij</mit></inf></rm><fen lp="par">1-<g>p</g><inf>ij</inf><rp
> post="par"/></fen>
> <sup>R<inf>j</inf>-m<inf>ij</inf></sup></fl></fd>
> </equation>
> <moretext></moretext> more text.
> </doc>
> -----------------------
> output: equations without text.
> 
> <equations>
> <inlineequation id="il1"><?Pub Eqn?>
> <f><rm><a><ac>CV</ac><ac>&d4;</ac></a><fen lp="par"><rm><g>q</g></rm>
> <rp post="par"/></fen></rm></f>
> </inlineequation>
> <equation id="eqn006"><?Pub Eqn?>
> <fd><fl><rm><?Eqn TeX input="\hskip -32pt\hbox to32pt{[6]}"?></rm>
> <rm>Prob<fen
> lp="par"><mit>m<inf>ij</inf>&vbm0;R<inf>j</inf><rm>,</rm>
> <g>p</g><inf>ij</inf></mit><rp post="par"/></fen>=<fen lp="par"><stk>
>
<lyr><mit>Rj</mit></lyr><lyr><it><mit>m<inf>ij</inf></mit></it></lyr></stk>
> <rp
> post="par"/></fen><g>p</g><sup><mit>m<inf>ij</inf></mit></sup><inf>
> <mit>ij</mit></inf></rm><fen lp="par">1-<g>p</g><inf>ij</inf><rp
> post="par"/></fen>
> <sup>R<inf>j</inf>-m<inf>ij</inf></sup></fl></fd>
> </equation>
> </equations>
> -----------------------
> stylesheet:
>   <xsl:template match="/">     
>      <equations>
>         <xsl:for-each select="//equation|//inlineequation" >
>           <xsl:copy>
>              <xsl:copy-of select="@*" />
>              <xsl:apply-templates select="node()" />
>              <xsl:apply-templates
> select="processing-instruction('Eqn')" />
>              <xsl:apply-templates
> select="processing-instruction('Pub')" />
>           </xsl:copy>
>         </xsl:for-each>
>      </equations>       
>   </xsl:template>
>   
>   <xsl:template match="node()">
>        <xsl:copy>
>             <xsl:copy-of select="@*" />
>             <xsl:apply-templates select="node()" />
>              <xsl:apply-templates
> select="processing-instruction('Eqn')" />
>              <xsl:apply-templates
> select="processing-instruction('Pub')" />
>        </xsl:copy>
>   </xsl:template>
>   
>   <xsl:template match="processing-instruction('Eqn')">
>       <!-- do nothing now -->
>   </xsl:template>
>   
>   <xsl:template match="processing-instruction('Pub')">
>       <!-- do nothing now, but want to keep -->
>   </xsl:template>
>  
> -----------------------
> desired output: (inline)equations only and without <?Eqn ...?> 
> <equations>
> <inlineequation id="il1"><?Pub Eqn?>
> <f><rm><a><ac>CV</ac><ac>&d4;</ac></a><fen lp="par"><rm><g>q</g></rm>
> <rp post="par"/></fen></rm></f>
> </inlineequation>
> <equation id="eqn006"><?Pub Eqn?>
> <fd><fl><rm></rm>
> <rm>Prob<fen
> lp="par"><mit>m<inf>ij</inf>&vbm0;R<inf>j</inf><rm>,</rm>
> <g>p</g><inf>ij</inf></mit><rp post="par"/></fen>=<fen lp="par"><stk>
>
<lyr><mit>Rj</mit></lyr><lyr><it><mit>m<inf>ij</inf></mit></it></lyr></stk>
> <rp
> post="par"/></fen><g>p</g><sup><mit>m<inf>ij</inf></mit></sup><inf>
> <mit>ij</mit></inf></rm><fen lp="par">1-<g>p</g><inf>ij</inf><rp
> post="par"/></fen>
> <sup>R<inf>j</inf>-m<inf>ij</inf></sup></fl></fd>
> </equation>
> </equations>
> -----------------------


This transformation can be simple, if implemented as customisation of
the identity rule:

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:template match="/">
    <equations>
      <xsl:apply-templates select="/*/node()"/>
    </equations>
  </xsl:template>
  
  <xsl:template match="@*|node()">
    <xsl:copy>
      <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
  </xsl:template>
  
  <xsl:template match="processing-instruction('Eqn')"/>
  <xsl:template match="text()[not(ancestor::equation 
                            or ancestor::inlineequation)]"/>
  <xsl:template match="*[not(ancestor::*[2]) and
                         not(self::equation 
                            or self::inlineequation
                            )
                         ]"/>
  
</xsl:stylesheet>



=====
Cheers,

Dimitre Novatchev.
http://fxsl.sourceforge.net/ -- the home of FXSL

__________________________________________________
Do You Yahoo!?
Yahoo! Health - Feel better, live better
http://health.yahoo.com

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


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.