Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. XML / XSL
  4. XSL Sum() [modified]

XSL Sum() [modified]

Scheduled Pinned Locked Moved XML / XSL
helpjavacssxmlquestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    LordLothar
    wrote on last edited by
    #1

    let say I have this:

    <books>
    <book>
    <title genre="non-fiction">Objects First With Java- A Practical Introduction Using Bluej </title>
    <author>David J. Barnes</author>
    <author>Michael Kolling</author>
    <publisher>Pearson Prentice Hall</publisher>
    <year>2006</year>
    <price>49</price>
    </book>
    <book>
    <title genre="fiction">Harry Potter and the Half-Blood Prince</title>
    <author>J. K. Rowling</author>
    <publisher>Thorndike Press</publisher>
    <year>2005</year>
    <price>29</price>
    </book>
    </books>

    and I want to sum the price if the title genre is fiction and book price is less than 30 (I should have more books for this but will add later). currently I read somewhere I came up with this:

    <xsl:value-of select="sum(/books/book/title[@genre='fiction']/price[number(text())<30])" />

    or this:

    <xsl:value-of select="sum(/books/book[title[@genre='fiction']]/price[number(text())<30])" />

    but it seems I still cant get it right. Anyone could help where I did wrong? Edited: I found the problem that I should use '& lt;30' instead of <30. I believe I did use lt before asking. Anyway, why the< b r / > in my xsl file does not work in FireFox but it is fine with IE? Many thanks.

    modified on Friday, April 17, 2009 8:28 AM

    G 1 Reply Last reply
    0
    • L LordLothar

      let say I have this:

      <books>
      <book>
      <title genre="non-fiction">Objects First With Java- A Practical Introduction Using Bluej </title>
      <author>David J. Barnes</author>
      <author>Michael Kolling</author>
      <publisher>Pearson Prentice Hall</publisher>
      <year>2006</year>
      <price>49</price>
      </book>
      <book>
      <title genre="fiction">Harry Potter and the Half-Blood Prince</title>
      <author>J. K. Rowling</author>
      <publisher>Thorndike Press</publisher>
      <year>2005</year>
      <price>29</price>
      </book>
      </books>

      and I want to sum the price if the title genre is fiction and book price is less than 30 (I should have more books for this but will add later). currently I read somewhere I came up with this:

      <xsl:value-of select="sum(/books/book/title[@genre='fiction']/price[number(text())<30])" />

      or this:

      <xsl:value-of select="sum(/books/book[title[@genre='fiction']]/price[number(text())<30])" />

      but it seems I still cant get it right. Anyone could help where I did wrong? Edited: I found the problem that I should use '& lt;30' instead of <30. I believe I did use lt before asking. Anyway, why the< b r / > in my xsl file does not work in FireFox but it is fine with IE? Many thanks.

      modified on Friday, April 17, 2009 8:28 AM

      G Offline
      G Offline
      George L Jackson
      wrote on last edited by
      #2

      You were almost there with your second effort: sum(/books/book[title[@genre = 'fiction']]/price[. &lt; 30])

      "We make a living by what we get, we make a life by what we give." --Winston Churchill

      L 1 Reply Last reply
      0
      • G George L Jackson

        You were almost there with your second effort: sum(/books/book[title[@genre = 'fiction']]/price[. &lt; 30])

        "We make a living by what we get, we make a life by what we give." --Winston Churchill

        L Offline
        L Offline
        LordLothar
        wrote on last edited by
        #3

        Using dot .& lt;30 seems to be working too and less confusing instead of number(text()). Thanks for your reply.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups