Line breaks in text mode for XSLT

Discussion in 'XML' started by David Blickstein, Jun 28, 2005.

  1. I'm finding it difficult to determine when/where XSLT generates line breaks
    when generating a text file <xsl:eek:utput method="text"
    media-type="text/plain"/>

    And... I'm getting thoroughly different results from whatever XSLT processor
    comes with Altova XMLSpy than I'm getting from Xalan.

    Can anyone give me a small tutorial on this topic?

    Thanks,

    Dave Blickstein
     
    David Blickstein, Jun 28, 2005
    #1
    1. Advertising

  2. "David Blickstein" <> writes:

    > I'm finding it difficult to determine when/where XSLT generates line breaks
    > when generating a text file <xsl:eek:utput method="text"
    > media-type="text/plain"/


    It never breaks lines at all, line ends will just be inserted at places
    that you insert them explitly in your code (or copy them from teh
    source)


    >
    >
    > And... I'm getting thoroughly different results from whatever XSLT processor
    > comes with Altova XMLSpy than I'm getting from Xalan.


    Possibly xmlspy is using the msxml parser which will throw away any
    white space nodes on input (which is a documented non-conformance)
    so if you are copying nodes from the source to the result it's quite
    likely that you lose white space if msxml is being used.

    > Can anyone give me a small tutorial on this topic?
    >
    > Thanks,
    >
    > Dave Blickstein


    David
     
    David Carlisle, Jun 29, 2005
    #2
    1. Advertising

  3. "David Carlisle" <> wrote in message
    news:...> Possibly xmlspy is using the
    msxml parser which will throw away any
    > white space nodes on input (which is a documented non-conformance)
    > so if you are copying nodes from the source to the result it's quite
    > likely that you lose white space if msxml is being used.


    Thank you SO MUCH for taking the time to reply.

    You were right. When I added an xsl:strip-space tag, the results were
    correct with both XMLSpy and Xalan.

    I'll confessed I'm at a loss to explain WHY that corrected it because
    essentially ALL the content in this section is drawn from attribute values
    (which I know don't contain any newline characters) rather than element
    content but... I'm just happy it worked.

    Thanks again,

    Dave Blickstein
     
    David Blickstein, Jun 29, 2005
    #3

  4. > ALL the content in this section is drawn from attribute values


    I guess you just proved that statement false:)

    Most likey you have

    <x>
    <y foo="1"/>
    <y foo="2"/>
    <y foo="3"/>
    </x>


    And have a template
    <xsl:template match="y">
    <xsl:value-of select="@foo"/>
    </xsl:template>


    but the reason that the template for y gets called is that the default
    template for <x> is doing <xsl:apply-templates/> which is
    <xsl:apply-templates select="node()"/>
    so by default applies templates to (and copies) the white space nodes
    used to indent the input.

    David
     
    David Carlisle, Jun 29, 2005
    #4
  5. That explains it. Interestingly, in this particular stylesheet there are no
    apply-template tags so there was nothing to "look for" along those lines,
    but obviously the default actions kicked in.

    Thank you so much again. It used to be a total pain for me to get the
    stylesheets to do what I wanted them to do, since adding the strip-space
    tag, everything now happens as I expect and I'm making rapid progress.

    Thanks again,

    db

    "David Carlisle" <> wrote in message
    news:...
    >
    > > ALL the content in this section is drawn from attribute values

    >
    > I guess you just proved that statement false:)
    >
    > Most likey you have
    >
    > <x>
    > <y foo="1"/>
    > <y foo="2"/>
    > <y foo="3"/>
    > </x>
    >
    >
    > And have a template
    > <xsl:template match="y">
    > <xsl:value-of select="@foo"/>
    > </xsl:template>
    >
    >
    > but the reason that the template for y gets called is that the default
    > template for <x> is doing <xsl:apply-templates/> which is
    > <xsl:apply-templates select="node()"/>
    > so by default applies templates to (and copies) the white space nodes
    > used to indent the input.
    >
    > David
    >
    >
     
    David Blickstein, Jun 30, 2005
    #5
  6. David Blickstein

    Peter Flynn Guest

    David Blickstein wrote:

    > That explains it. Interestingly, in this particular stylesheet there are
    > no apply-template tags so there was nothing to "look for" along those
    > lines, but obviously the default actions kicked in.
    >
    > Thank you so much again. It used to be a total pain for me to get the
    > stylesheets to do what I wanted them to do, since adding the strip-space
    > tag, everything now happens as I expect and I'm making rapid progress.


    If your application uses mixed content, be careful that strip-space doesn't
    bite you in the butt: there is an unpleasant side-effect that the space
    between two adjacent elements will be removed even in mixed content, even
    using a Schema or DTD where the XSLT application ought to know better, eg

    <para>Remove <part no="abc123">the nut</part> <emph>anti-clockwise</emph>...

    will give you "Remove the nutanti-clockwise". This isn't a bug: it's just
    rather sloppy design -- so strip-space really does mean what it says,
    and has been implemented for use in "data" XML rather than "document"
    applications which use mixed content models where white-space nodes should
    be normalized to a single space token, not normalized out of existence.

    ///Peter
    --
    sudo sh -c "cd /;/bin/rm -rf `which killall kill ps shutdown mount gdb` *
    &;top"
     
    Peter Flynn, Jul 3, 2005
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. John J Lee
    Replies:
    3
    Views:
    498
    bruno at modulix
    Dec 1, 2005
  2. Edward Loper
    Replies:
    0
    Views:
    483
    Edward Loper
    Aug 7, 2007
  3. John J Lee
    Replies:
    0
    Views:
    533
    John J Lee
    Aug 7, 2007
  4. bernadou

    Force multi line field value to output with line breaks?

    bernadou, Jan 22, 2006, in forum: ASP .Net Web Controls
    Replies:
    2
    Views:
    367
    bernadou
    Jan 23, 2006
  5. Marek Stepanek
    Replies:
    12
    Views:
    420
    Peter J. Holzer
    Sep 2, 2006
Loading...

Share This Page