Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > transformation in text-mode

Reply
Thread Tools

transformation in text-mode

 
 
=?ISO-8859-1?Q?J=FCrgen_Holly?=
Guest
Posts: n/a
 
      07-29-2003
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
 
Reply With Quote
 
 
 
 
Dimitre Novatchev
Guest
Posts: n/a
 
      07-29-2003
By definition the setting method="text" in xslutput 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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) om...
> 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 xslutput 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






 
Reply With Quote
 
 
 
 
Andy Fish
Guest
Posts: n/a
 
      07-30-2003
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) om...
> 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



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Query Regarding 2D wavelet transformation Bakkurudeen Ali J VHDL 0 09-14-2004 01:53 PM
Firefox XML Transformation Grinder Firefox 0 07-29-2004 05:07 AM
Timeout on Xsl Transformation George Durzi ASP .Net 0 12-29-2003 07:46 PM
Need example of events fired from xmlDocument html transformation KathyB ASP .Net 0 07-19-2003 03:30 PM
Need help on SQL-Server Network Data Transformation Muhammad Qasim MCSD 1 07-09-2003 08:40 AM



Advertisments