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. where did the whitespace go? [modified]

where did the whitespace go? [modified]

Scheduled Pinned Locked Moved XML / XSL
xmlhtmlhelptutorialquestion
12 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.
  • B Bluebamboo

    Hi all, I'm having a problem with my XSL converting to HTML. I can view all content fine, except the white space is not preserved! I've tried all relevant attributes such as xml:space, xsl:preserve-space, bt don't work :(:(:(:(:(:(:(:(:(:( For example in my XML: <catalog> <content> lines and lines of text more text </content> </catalog> When transforming I get: lines and lines of text more text It's all bunched up...where did the newline characters go? my XSL contains this: <xsl:value-of select="content"/> Any ideas? Thanks. -- modified at 11:55 Thursday 29th June, 2006

    D Offline
    D Offline
    Dustin Metzgar
    wrote on last edited by
    #2

    In order for your message to show correctly you have to use < to create the < and > to create the > signs. Anyways, this typically happens when doing an XSL transform. If you're coding the transformation yourself in .NET, you can put settings on the XmlTextWriter that will handle the spacing. If you're using a tool like XmlSpy, you can do a pretty print.  There might be settings on the transformation software you're using to format the output.


    Logifusion[^]

    B 1 Reply Last reply
    0
    • D Dustin Metzgar

      In order for your message to show correctly you have to use < to create the < and > to create the > signs. Anyways, this typically happens when doing an XSL transform. If you're coding the transformation yourself in .NET, you can put settings on the XmlTextWriter that will handle the spacing. If you're using a tool like XmlSpy, you can do a pretty print.  There might be settings on the transformation software you're using to format the output.


      Logifusion[^]

      B Offline
      B Offline
      Bluebamboo
      wrote on last edited by
      #3

      thanks. i think you might misunderstand my issue, the problem is about how to transform xml to html with all whitespace which the xml file has, not about the pretty print.;) plz help me

      D 1 Reply Last reply
      0
      • B Bluebamboo

        thanks. i think you might misunderstand my issue, the problem is about how to transform xml to html with all whitespace which the xml file has, not about the pretty print.;) plz help me

        D Offline
        D Offline
        Dustin Metzgar
        wrote on last edited by
        #4

        Well, I am doing the same thing as you. I pass some XML through a stylesheet to create HTML. The source is all cramped together, but I don't mind much as long as the HTML comes out ok. But sometimes it doesn't. For instance, if I want a space between two items like so:

        <xsl:value-of select="$data/ch2_State"/> <xsl:value-of select="$data/vch10_ZipCode"/>

        XSL will strip out the space between the state and the zip code so it looks like this: NY12345 That's a real pain. And, like you say, preserve space and whatever else you put there just doesn't work. So, what I ended up doing was this:

        <xsl:value-of select="$data/ch2_State"/>
        <xsl:text disable-output-escaping="yes">&</xsl:text>nbsp;
        <xsl:value-of select="$data/vch10_ZipCode"/>

        It's an extra annoyance, but it gets the job done.


        Logifusion[^]

        B 1 Reply Last reply
        0
        • D Dustin Metzgar

          Well, I am doing the same thing as you. I pass some XML through a stylesheet to create HTML. The source is all cramped together, but I don't mind much as long as the HTML comes out ok. But sometimes it doesn't. For instance, if I want a space between two items like so:

          <xsl:value-of select="$data/ch2_State"/> <xsl:value-of select="$data/vch10_ZipCode"/>

          XSL will strip out the space between the state and the zip code so it looks like this: NY12345 That's a real pain. And, like you say, preserve space and whatever else you put there just doesn't work. So, what I ended up doing was this:

          <xsl:value-of select="$data/ch2_State"/>
          <xsl:text disable-output-escaping="yes">&</xsl:text>nbsp;
          <xsl:value-of select="$data/vch10_ZipCode"/>

          It's an extra annoyance, but it gets the job done.


          Logifusion[^]

          B Offline
          B Offline
          Bluebamboo
          wrote on last edited by
          #5

          it is also one of solutions, but what i'm aim to do is to write a xsl file, and i use this xsl to transform all articles which stored in xml file. So the positions of carriage return in each article are random. do you have any solution to deal with it? thanks?

          D 1 Reply Last reply
          0
          • B Bluebamboo

            it is also one of solutions, but what i'm aim to do is to write a xsl file, and i use this xsl to transform all articles which stored in xml file. So the positions of carriage return in each article are random. do you have any solution to deal with it? thanks?

            D Offline
            D Offline
            Dustin Metzgar
            wrote on last edited by
            #6

            In one situation where I needed the HTML to look exactly a certain way, I changed my output type from HTML to Text. This way, the stylesheet had to pay more attention to me. The stylesheet was harder to write because you have to enclose things in xsl:text tags, but it got the job done. To do a new line, you can do something like this:

            xsl:text
            </xsl:text>

            or

            xsl:text </xsl:text>

            Even if the target is set to Text, XSL still likes to get rid of whitespace, so it's a lot of trial and error. I hope that helps. If you find an easier solution, I'd be happy to hear it!


            Logifusion[^]

            B 1 Reply Last reply
            0
            • D Dustin Metzgar

              In one situation where I needed the HTML to look exactly a certain way, I changed my output type from HTML to Text. This way, the stylesheet had to pay more attention to me. The stylesheet was harder to write because you have to enclose things in xsl:text tags, but it got the job done. To do a new line, you can do something like this:

              xsl:text
              </xsl:text>

              or

              xsl:text </xsl:text>

              Even if the target is set to Text, XSL still likes to get rid of whitespace, so it's a lot of trial and error. I hope that helps. If you find an easier solution, I'd be happy to hear it!


              Logifusion[^]

              B Offline
              B Offline
              Bluebamboo
              wrote on last edited by
              #7

              oh god! i tried your way to do a new line with tags: xsl:text </xsl:text> it's just displayed a space instead of carriage return. what's wrong? -- modified at 17:51 Thursday 29th June, 2006

              D 1 Reply Last reply
              0
              • B Bluebamboo

                oh god! i tried your way to do a new line with tags: xsl:text </xsl:text> it's just displayed a space instead of carriage return. what's wrong? -- modified at 17:51 Thursday 29th June, 2006

                D Offline
                D Offline
                Dustin Metzgar
                wrote on last edited by
                #8

                Ya, unfortunately that way works with some XSL transformers and not with others. It's really quite annoying. You might want to use the other method instead. I'm not sure if you have to escape it or not, but this seemed to work pretty well for one guy at work. The only trouble is that it makes the XSL really ugly.

                Logifusion[^]

                B 1 Reply Last reply
                0
                • D Dustin Metzgar

                  Ya, unfortunately that way works with some XSL transformers and not with others. It's really quite annoying. You might want to use the other method instead. I'm not sure if you have to escape it or not, but this seemed to work pretty well for one guy at work. The only trouble is that it makes the XSL really ugly.

                  Logifusion[^]

                  B Offline
                  B Offline
                  Bluebamboo
                  wrote on last edited by
                  #9

                  yes, i tried to enter <cr/> tag (my self-define tag )to substitute each CARRIAGE RETURN, when i am entering content of my article into xml file, and make relevant manipulation for this tag in xsl file. however, i meet another problem:((, how to find out all <cr/> tags in a xml file? because this tag can be existed in different hierarchy of xml file. any ideas? many thanks

                  D T 2 Replies Last reply
                  0
                  • B Bluebamboo

                    yes, i tried to enter <cr/> tag (my self-define tag )to substitute each CARRIAGE RETURN, when i am entering content of my article into xml file, and make relevant manipulation for this tag in xsl file. however, i meet another problem:((, how to find out all <cr/> tags in a xml file? because this tag can be existed in different hierarchy of xml file. any ideas? many thanks

                    D Offline
                    D Offline
                    Dustin Metzgar
                    wrote on last edited by
                    #10

                    That sounds difficult. Is it that you have text in your XML document that has newlines in it and you want the formatting to be the same in the HTML? If you have the ability to, you might want to try putting it into a CDATA in the XML. After switching to text output, I was able to get my stylesheets working the way I wanted them to.


                    Logifusion[^]

                    1 Reply Last reply
                    0
                    • B Bluebamboo

                      yes, i tried to enter <cr/> tag (my self-define tag )to substitute each CARRIAGE RETURN, when i am entering content of my article into xml file, and make relevant manipulation for this tag in xsl file. however, i meet another problem:((, how to find out all <cr/> tags in a xml file? because this tag can be existed in different hierarchy of xml file. any ideas? many thanks

                      T Offline
                      T Offline
                      Tuwing Sabado
                      wrote on last edited by
                      #11

                      Define a template match for your <cr> node. In the absence of a select attribute, the xsl:apply-templates instruction processes all of the children of the current node, including text nodes. Tutorial for XSLT : http://www.zvon.org/xxl/XSLTreference/Output/index.html[^]

                      B 1 Reply Last reply
                      0
                      • T Tuwing Sabado

                        Define a template match for your <cr> node. In the absence of a select attribute, the xsl:apply-templates instruction processes all of the children of the current node, including text nodes. Tutorial for XSLT : http://www.zvon.org/xxl/XSLTreference/Output/index.html[^]

                        B Offline
                        B Offline
                        Bluebamboo
                        wrote on last edited by
                        #12

                        THanks everyone. finally, I use <xsl:copy-of select="./node()"/>to address my problem. Thanks for the Url you provided, it is very helpful.:)

                        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