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

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


Subject: [xsl] RE : [xsl] counting the preceding cousins of an element
From: Florent Georges <darkman_spam@xxxxxxxx>
Date: Thu, 15 Jun 2006 10:40:48 +0200 (CEST)

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="//*[@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 sollicitis 
http://mail.yahoo.fr Yahoo! Mail 


Current Thread
Keywords