Hopefully simple XPath question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jon Thackray

    Hopefully simple XPath question

    I'm trying to use XPath to enable me to number items within sections
    in a paper. I have so far tried about ten things, all of which it
    seemed to me should work, and none of which do. Essentially what I
    want is a count of the number of sections preceding the section which
    is (the unique section) ancestor of the current node. Functionally
    this would be

    #PrecedingSibli ngs(SectionAnce storOf(CurrentN ode))

    But XPath doesn't seem to allow me to express this . I've no doubt it
    can, I just can't currently see how. Can somebody please enlighten me.
  • Joris Gillis

    #2
    Re: Hopefully simple XPath question

    Hi,
    [color=blue]
    > Essentially what I want is a count of the number ofsections preceding the section which is (the uniquesection) ancestor of the current node.[/color]

    In Xpath, it would be: count(preceding ::section)

    but, it is more advisable to use the xslt approach, viz. 'xsl:number'
    so you should use something like: <xsl:number level="any" count="section"/>
    for full details, see http://www.w3.org/TR/xslt.html#number

    regards,
    --
    Joris Gillis (http://www.ticalc.org/cgi-bin/acct-v...i?userid=38041)
    Ceterum censeo XML omnibus esse utendum

    Comment

    • Jon Thackray

      #3
      Re: Hopefully simple XPath question

      jgt@pobox.com (Jon Thackray) wrote in message news:<518891d6. 0411101518.2c6c a258@posting.go ogle.com>...
      Snip

      No answer required any more, I've figured it out.

      Comment

      • Jeff Kish

        #4
        Re: Hopefully simple XPath question

        On 11 Nov 2004 13:48:55 -0800, jgt@pobox.com (Jon Thackray) wrote:
        [color=blue]
        >jgt@pobox.co m (Jon Thackray) wrote in message news:<518891d6. 0411101518.2c6c a258@posting.go ogle.com>...
        >Snip
        >
        >No answer required any more, I've figured it out.[/color]
        And the answer is... ?

        Comment

        • Jeff Kish

          #5
          Re: Hopefully simple XPath question

          On Thu, 11 Nov 2004 18:56:29 GMT, "Joris Gillis" <roac@pandora.b e> wrote:
          [color=blue]
          >Hi,
          >[color=green]
          >> Essentially what I want is a count of the number ofsections preceding the section which is (the uniquesection) ancestor of the current node.[/color]
          >
          >In Xpath, it would be: count(preceding ::section)
          >
          >but, it is more advisable to use the xslt approach, viz. 'xsl:number'
          >so you should use something like: <xsl:number level="any" count="section"/>
          >for full details, see http://www.w3.org/TR/xslt.html#number
          >
          >regards,[/color]
          Just out of curiosity, why is it more advisable? Just trying to learn here.
          Thanks

          Comment

          • Joris Gillis

            #6
            Re: Hopefully simple XPath question

            >> but, it is more advisable to use the xslt approach, viz. 'xsl:number'[color=blue]
            > Just out of curiosity, why is it more advisable? Just trying to learn here.
            > Thanks
            >[/color]
            Hi,

            It was only my own humble opinion :) , I should have mentioned that...
            Since xslt defines a (flexible) numbering system (with quite advanced features), I see no need to invent a similar function (bound to very complicated when mimicing some features of 'xsl:number') by using Xpath. So, I prefer 'xsl:number' just to keep my code neat, flexible, extensible and comprehensible.

            You don't have to agree off course. I'm just learning too.

            regards,

            --
            Joris Gillis (http://www.ticalc.org/cgi-bin/acct-v...i?userid=38041)
            Ceterum censeo XML omnibus esse utendum

            Comment

            • Jon Thackray

              #7
              Re: Hopefully simple XPath question

              "Joris Gillis" <roac@pandora.b e> wrote in message news:<opshbdq2j iyf9v9r@news.pa ndora.be>...[color=blue]
              > Hi,
              >[color=green]
              > > Essentially what I want is a count of the number ofsections preceding the section which is (the uniquesection) ancestor of the current node.[/color]
              >
              > In Xpath, it would be: count(preceding ::section)[/color]

              That doesn't quite do it. I ended up with this

              <xsl:value-of select="1+count (ancestor::SECT ION/preceding-sibling::SECTIO N)"/>
              [color=blue]
              > but, it is more advisable to use the xslt approach, viz. 'xsl:number'
              > so you should use something like: <xsl:number level="any" count="section"/>
              > for full details, see http://www.w3.org/TR/xslt.html#number[/color]

              I'll look into that.

              Comment

              • Joris Gillis

                #8
                Re: Hopefully simple XPath question

                >> In Xpath, it would be: count(preceding ::section)[color=blue]
                >
                > That doesn't quite do it. I ended up with this
                >
                > <xsl:value-of select="1+count (ancestor::SECT ION/preceding-sibling::SECTIO N)"/>[/color]

                That's strange, I would have sworn that "count(ancestor ::SECTION/preceding-sibling::SECTIO N)" gave the same result as "count(precedin g::section)" in your xml (or what I understood of it).
                The '+1' change is logic off course.

                regards,
                --
                Joris Gillis (http://www.ticalc.org/cgi-bin/acct-v...i?userid=38041)
                Ceterum censeo XML omnibus esse utendum

                Comment

                • Jon Thackray

                  #9
                  Re: Hopefully simple XPath question

                  "Joris Gillis" <roac@pandora.b e> wrote in message news:<opshc973s eyf9v9r@news.pa ndora.be>...[color=blue][color=green][color=darkred]
                  > >> In Xpath, it would be: count(preceding ::section)[/color]
                  > >
                  > > That doesn't quite do it. I ended up with this
                  > >
                  > > <xsl:value-of select="1+count (ancestor::SECT ION/preceding-sibling::SECTIO N)"/>[/color]
                  >
                  > That's strange, I would have sworn that "count(ancestor ::SECTION/preceding-sibling::SECTIO N)" gave the same result as "count(precedin g::section)" in your xml (or what I understood of it).[/color]

                  It went wrong in the second CHAPTER. Given document structure below,
                  1+count(precedi ng::SECTION) gave

                  CHAPTER
                  SECTION Items numbered 1.1.x
                  SECTION Items numbered 1.2.x
                  SECTION Items numbered 1.3.x
                  CHAPTER
                  SECTION Items numbered 2.4.x

                  Where I wanted

                  CHAPTER
                  SECTION Items numbered 1.1.x
                  SECTION Items numbered 1.2.x
                  SECTION Items numbered 1.3.x
                  CHAPTER
                  SECTION Items numbered 2.1.x
                  [color=blue]
                  > The '+1' change is logic off course.[/color]

                  Just making it 1 based rather then 0 based

                  Comment

                  • Joris Gillis

                    #10
                    Re: Hopefully simple XPath question

                    > I wanted[color=blue]
                    >
                    > CHAPTER
                    > SECTION Items numbered 1.1.x
                    > SECTION Items numbered 1.2.x
                    > SECTION Items numbered 1.3.x
                    > CHAPTER
                    > SECTION Items numbered 2.1.x[/color]

                    OK, I see.

                    with 'xsl:number', it would be something like:

                    <xsl:number level="any" count="CHAPTER"/><xsl:text>.</xsl:text>
                    <xsl:number level="any" from="CHAPTER" count="SECTION"/>

                    regards,
                    --
                    Joris Gillis (http://www.ticalc.org/cgi-bin/acct-v...i?userid=38041)
                    Ceterum censeo XML omnibus esse utendum

                    Comment

                    Working...