Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   XML (http://www.velocityreviews.com/forums/f32-xml.html)
-   -   transformation in text-mode (http://www.velocityreviews.com/forums/t165261-transformation-in-text-mode.html)

=?ISO-8859-1?Q?J=FCrgen_Holly?= 07-29-2003 03:08 PM

transformation in text-mode
 
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

Dimitre Novatchev 07-29-2003 09:03 PM

Re: transformation in text-mode
 
By definition the setting method="text" in xsl:output 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" <juergen.holly@immorent.at> wrote in message
news:2b5c087e.0307290708.67c10841@posting.google.c 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 xsl:output 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







Andy Fish 07-30-2003 03:26 PM

Re: transformation in text-mode
 
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" <juergen.holly@immorent.at> wrote in message
news:2b5c087e.0307290708.67c10841@posting.google.c 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





All times are GMT. The time now is 10:01 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.