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. Trim all innertext/attributes values with XSL

Trim all innertext/attributes values with XSL

Scheduled Pinned Locked Moved XML / XSL
xmljsonquestion
8 Posts 3 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.
  • T Offline
    T Offline
    Tony Pottier
    wrote on last edited by
    #1

    Hi, I'm parsing a fixed size flat file document and convert it into XML, but I therefore have output like

    <root>
    <foo bar=" lulz "> zomg </foo>
    <hello> world</hello>
    </root>

    Which I'd like to look like:

    <root>
    <foo bar="lulz">zomg</foo>
    <hello>world</hello>
    </root>

    Is there a way to do this with XSLT? I've tryed a copy/copy-of and normalize-space, but it doesn't give me the output I'd want. This is driving me insane. Thanks!

    L G 2 Replies Last reply
    0
    • T Tony Pottier

      Hi, I'm parsing a fixed size flat file document and convert it into XML, but I therefore have output like

      <root>
      <foo bar=" lulz "> zomg </foo>
      <hello> world</hello>
      </root>

      Which I'd like to look like:

      <root>
      <foo bar="lulz">zomg</foo>
      <hello>world</hello>
      </root>

      Is there a way to do this with XSLT? I've tryed a copy/copy-of and normalize-space, but it doesn't give me the output I'd want. This is driving me insane. Thanks!

      L Offline
      L Offline
      led mike
      wrote on last edited by
      #2

      Tony_P wrote:

      I'm parsing a fixed size flat file document and convert it into XML

      Why don't you trim the spaces during the parsing/processing of the flat file?

      T 1 Reply Last reply
      0
      • L led mike

        Tony_P wrote:

        I'm parsing a fixed size flat file document and convert it into XML

        Why don't you trim the spaces during the parsing/processing of the flat file?

        T Offline
        T Offline
        Tony Pottier
        wrote on last edited by
        #3

        That'd be indeed nice but it's document generated by webMethods, I can't do that.

        L 1 Reply Last reply
        0
        • T Tony Pottier

          That'd be indeed nice but it's document generated by webMethods, I can't do that.

          L Offline
          L Offline
          led mike
          wrote on last edited by
          #4

          Ok, I'm lost now. Good luck

          1 Reply Last reply
          0
          • T Tony Pottier

            Hi, I'm parsing a fixed size flat file document and convert it into XML, but I therefore have output like

            <root>
            <foo bar=" lulz "> zomg </foo>
            <hello> world</hello>
            </root>

            Which I'd like to look like:

            <root>
            <foo bar="lulz">zomg</foo>
            <hello>world</hello>
            </root>

            Is there a way to do this with XSLT? I've tryed a copy/copy-of and normalize-space, but it doesn't give me the output I'd want. This is driving me insane. Thanks!

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

            You can use translate, a XPath function, with an empty replace string. translate($data, " ", "")

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

            T 1 Reply Last reply
            0
            • G George L Jackson

              You can use translate, a XPath function, with an empty replace string. translate($data, " ", "")

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

              T Offline
              T Offline
              Tony Pottier
              wrote on last edited by
              #6

              This cannot work as you need to know the structure of the document to apply translate. I don't think this is possible, I've been searching the whole internet, and nothing came up. XSLT is such a stupid standard.

              L G 2 Replies Last reply
              0
              • T Tony Pottier

                This cannot work as you need to know the structure of the document to apply translate. I don't think this is possible, I've been searching the whole internet, and nothing came up. XSLT is such a stupid standard.

                L Offline
                L Offline
                led mike
                wrote on last edited by
                #7

                Tony_P wrote:

                XSLT is such a stupid standard.

                Sure it is. :rolleyes: Ever listen to any Led Zeppelin? You might want to check this song out[^].

                1 Reply Last reply
                0
                • T Tony Pottier

                  This cannot work as you need to know the structure of the document to apply translate. I don't think this is possible, I've been searching the whole internet, and nothing came up. XSLT is such a stupid standard.

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

                  If you are using .NET, have you considered using Script Blocks using msxsl:script to create your own XSLT trimming function? An even better solution is to use XsltArgumentList. Also, what is normalize-space not doing to fit your needs?

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

                  modified on Friday, February 13, 2009 11:56 AM

                  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