transformation in text-mode

Discussion in 'XML' started by =?ISO-8859-1?Q?J=FCrgen_Holly?=, Jul 29, 2003.

  1. Hi!

    I have the following xml-node:

    <docu>
    <p>Sample: <b>bold</b></p>
    <p>and text in <i>italic</i></p>
    </docu>

    I need to create a text-file, so I set the output-mode to text.
    In a docu-node you can write normal text and additionally html-tags.

    In the text-file I should output that:

    "<p>Sample: <b>bold</b></p><p>and text in <i>italic</i></p>"

    i.e. compress text between <docu> and </docu> in a single line.
    I wrote this template - but it dont't work. The html-tags are filtered
    out and the linebreak is still there.

    <xsl:template match="docu">
    <xsl:copy-of select="."/>
    </xsl:template>

    In html-mode the html-tags will be copied.
    How can I do this??

    Thanx for help!
    Jürgen
     
    =?ISO-8859-1?Q?J=FCrgen_Holly?=, Jul 29, 2003
    #1
    1. Advertising

  2. By definition the setting method="text" in xsl:eek:utput should only output
    the contents of the text nodes in the result tree:

    "16.3 Text Output Method
    The text output method outputs the result tree by outputting the
    string-value of every text node in the result tree in document order without
    any escaping."

    http://www.w3.org/TR/xslt#section-Text-Output-Method







    "Jürgen Holly" <> wrote in message
    news:...
    > Hi!
    >
    > I have the following xml-node:
    >
    > <docu>
    > <p>Sample: <b>bold</b></p>
    > <p>and text in <i>italic</i></p>
    > </docu>
    >
    > I need to create a text-file, so I set the output-mode to text.
    > In a docu-node you can write normal text and additionally html-tags.
    >
    > In the text-file I should output that:
    >
    > "<p>Sample: <b>bold</b></p><p>and text in <i>italic</i></p>"
    >
    > i.e. compress text between <docu> and </docu> in a single line.
    > I wrote this template - but it dont't work. The html-tags are filtered
    > out and the linebreak is still there.


    By definition the setting method="text" in xsl:eek:utput should only output
    the contents of the text nodes in the result tree:

    "16.3 Text Output Method
    The text output method outputs the result tree by outputting the
    string-value of every text node in the result tree in document order without
    any escaping."

    http://www.w3.org/TR/xslt#section-Text-Output-Method

    Therefore, if you need the element nodes copied, you must node use
    method="text".

    >
    > <xsl:template match="docu">
    > <xsl:copy-of select="."/>
    > </xsl:template>
    >
    > In html-mode the html-tags will be copied.
    > How can I do this??



    You must read all about whitespace nodes processing in xslt.

    The above xsl:copy-of in your code copies the subtree with root the current
    node ("docu") and this includes all of its whitespace-only descendents.

    In case you do not need to process whitespace only nodes in your document,
    you can use:



    <xsl:strip-space elements="*"/>

    This specifies that the whetespace-only text nodes of all elements are to be
    striped.

    In case you only need to ignore whitespace-only children of specific
    elements and presereve the whitespace-only children for others, then you
    must explicitly specify the value of the "elements" attribute of
    xsl:strip-space as a blank-separated list of element names, whose
    children-whitespace-only-text nodes are to be stripped.



    =====
    Cheers,

    Dimitre Novatchev.
    http://fxsl.sourceforge.net/ -- the home of FXSL
     
    Dimitre Novatchev, Jul 29, 2003
    #2
    1. Advertising

  3. =?ISO-8859-1?Q?J=FCrgen_Holly?=

    Andy Fish Guest

    if the majority of your output file is xml (or html) and only a few bits
    aren't, you can use disable-output-escaping on only those sections which
    need text mode output. otherwise you will need to do something like this:

    <xsl:template match="docu//*">
    &lt;<xsl:value-of
    select="name()">&gt;<xsl:apply-templates/>&lt;/<xsl:value-of
    select="name()">&gt;
    </xsl:template>

    however, your other problem is you are not processing whitespace properly.
    If you want to remove whitespace nodes from the result tree you will need to
    exclude them when calling apply-templates. try something like

    <xsl:apply-templates select="*|@*">

    which will only select sub-elements and attributes, rather than the default
    which selects all child nodes (sorry - neither of these two examples are
    tested)

    Andy

    "Jürgen Holly" <> wrote in message
    news:...
    > Hi!
    >
    > I have the following xml-node:
    >
    > <docu>
    > <p>Sample: <b>bold</b></p>
    > <p>and text in <i>italic</i></p>
    > </docu>
    >
    > I need to create a text-file, so I set the output-mode to text.
    > In a docu-node you can write normal text and additionally html-tags.
    >
    > In the text-file I should output that:
    >
    > "<p>Sample: <b>bold</b></p><p>and text in <i>italic</i></p>"
    >
    > i.e. compress text between <docu> and </docu> in a single line.
    > I wrote this template - but it dont't work. The html-tags are filtered
    > out and the linebreak is still there.
    >
    > <xsl:template match="docu">
    > <xsl:copy-of select="."/>
    > </xsl:template>
    >
    > In html-mode the html-tags will be copied.
    > How can I do this??
    >
    > Thanx for help!
    > Jürgen
     
    Andy Fish, Jul 30, 2003
    #3
    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:
    492
    bruno at modulix
    Dec 1, 2005
  2. Edward Loper
    Replies:
    0
    Views:
    478
    Edward Loper
    Aug 7, 2007
  3. John J Lee
    Replies:
    0
    Views:
    531
    John J Lee
    Aug 7, 2007
  4. Edward Loper

    mmm-mode, python-mode and doctest-mode?

    Edward Loper, Aug 9, 2007, in forum: Python
    Replies:
    0
    Views:
    441
    Edward Loper
    Aug 9, 2007
  5. Neal Becker
    Replies:
    0
    Views:
    383
    Neal Becker
    Aug 9, 2007
Loading...

Share This Page