xsl-list
[Top] [All Lists]

[xsl] RE : [xsl] counting the preceding cousins of an element

2006-06-15 01:41:14
Carlo Liwanag wrote:

In this example, the footnote is the element and the ancestor
is the chapter.
How can I find the
preceding::footnote[ancestor::chapter[descendant::"is 
the current node"]]?

  If I understand right, you can use the following in XSLT 2.0:

    ~> cat preceding-cousin.xsl
    <xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
                   version="2.0">

      <xsl:output indent="yes"/>

      <xsl:variable name="ref"     select="//*[(_at_)id eq '15']"/>
      <xsl:variable name="chapter" select="$ref/ancestor::chapter[1]"/>

      <xsl:template match="/">
        <xsl:copy-of select="$chapter//footnote[. &lt;&lt; $ref]"/>
      </xsl:template>

    </xsl:transform>

    ~> cat preceding-cousin.xml
    <root>
      <chapter>
          <para>
             some text here
             <footnote id="01"/>
                 some text here
             <footnote id="02"/>
          </para>
          <para>
              some text here
             <footnote id="03"/>
                 some text here
             <footnote id="04"/>
             some text here
             <footnote id="05"/>
                 some text here
             <footnote id="06"/>
          </para>
          <para>
             some text here
             <footnote id="07"/>
                 some text here
             <footnote id="08"/>
          </para>
      </chapter>
      <chapter>
          <para>
             some text here
             <footnote id="11"/>
                 some text here
             <footnote id="12"/>
          </para>
          <para>
              some text here
             <footnote id="13"/>
                 some text here
             <footnote id="14"/>
             some text here
             <footnote id="15"/>
                 some text here
             <footnote id="16"/>
          </para>
          <para>
             some text here
             <footnote id="17"/>
                 some text here
             <footnote id="18"/>
          </para>
      </chapter>
      <chapter>
          <para>
             some text here
             <footnote id="21"/>
                 some text here
             <footnote id="22"/>
          </para>
          <para>
              some text here
             <footnote id="23"/>
                 some text here
             <footnote id="24"/>
             some text here
             <footnote id="25"/>
                 some text here
             <footnote id="26"/>
          </para>
          <para>
             some text here
             <footnote id="27"/>
                 some text here
             <footnote id="28"/>
          </para>
      </chapter>
    </root>

    ~> saxon preceding-cousin.xml preceding-cousin.xsl
    <?xml version="1.0" encoding="UTF-8"?>
    <footnote id="11"/>
    <footnote id="12"/>
    <footnote id="13"/>
    <footnote id="14"/>

  Regards,

--drkm

























__________________________________________________
Do You Yahoo!?
En finir avec le spam? Yahoo! Mail vous offre la meilleure protection possible 
contre les messages non sollicités 
http://mail.yahoo.fr Yahoo! Mail 

--~------------------------------------------------------------------
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>
--~--

<Prev in Thread] Current Thread [Next in Thread>