xsl-list
[Top] [All Lists]

Re: [xsl] Find out the existance of an element between 2 others

2006-11-14 08:39:22
Ed Yau wrote:

  Hi

What I am trying to express in an Xpath is "Look to see
where there are any <w:t> elements containing text between
these 2 <w:br>s".

  What your are looking for is computing the intersection
between two sets.  In XPath 2.0, you have the 'intersect'
operator.  In XSLT 1.0, you can use the following technique,
using the fact that nodes appearing in two sets don't modify
the count of the elements in one set.  Strangely, I didn't
find reference to this in the FAQ, Dave.  Maybe I didn't
look at the right place?

    [29] ~/xslt/tests$ cat intersect.xml
    <root xmlns:w="WordML">
      <w:t id="a"/>
      <w:br/>
      <w:t id="b"/>
      <w:t id="c"/>
      <w:br/>
      <w:t id="d"/>
      <w:br/>
      <w:t id="e"/>
    </root>

    [30] ~/xslt/tests$ cat intersect.xsl
    <xsl:transform
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
        xmlns:w="WordML"
        version="1.0">

      <xsl:output omit-xml-declaration="yes" indent="yes"/>

      <xsl:variable name="after-1st"  select="
          /*/w:br[1]/following-sibling::w:t"/>
      <xsl:variable name="before-2nd" select="
          /*/w:br[2]/preceding-sibling::w:t"/>
      <xsl:variable name="intersect"  select="
          $after-1st[count(.|$before-2nd) = count($before-2nd)]"/>

      <xsl:template match="/">
        <result>
          <xsl:copy-of select="$intersect"/>
        </result>
      </xsl:template>

    </xsl:transform>

    [31] ~/xslt/tests$ xalan -XSL intersect.xsl -IN intersect.xml
    <result xmlns:w="WordML">
    <w:t id="b"/>
    <w:t id="c"/>
    </result>

    [32] ~/xslt/tests$ xsltproc intersect.xsl intersect.xml
    <result xmlns:w="WordML">
      <w:t id="b"/>
      <w:t id="c"/>
    </result>

    [33] ~/xslt/tests$ saxon intersect.xml intersect.xsl
    Warning: at xsl:transform on line 4 of ~/xslt/tests/intersect.xsl:
      Running an XSLT 1.0 stylesheet with an XSLT 2.0 processor
    <result xmlns:w="WordML">
       <w:t id="b"/>
       <w:t id="c"/>
    </result>

  Regards,

--drkm




















        

        
                
___________________________________________________________________________ 
Découvrez une nouvelle façon d'obtenir des réponses à toutes vos questions ! 
Profitez des connaissances, des opinions et des expériences des internautes sur 
Yahoo! Questions/Réponses 
http://fr.answers.yahoo.com

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--