transformation in text-mode

  • Thread starter =?ISO-8859-1?Q?J=FCrgen_Holly?=
  • Start date
?

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

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
 
D

Dimitre Novatchev

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 said:
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
 
A

Andy Fish

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top