473,657 Members | 2,800 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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
Jul 20 '05 #1
2 2873
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" <ju***********@ immorent.at> wrote in message
news:2b******** *************** ***@posting.goo gle.com...
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


Jul 20 '05 #2
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:val ue-of
select="name()" >&gt;<xsl:app ly-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" <ju***********@ immorent.at> wrote in message
news:2b******** *************** ***@posting.goo gle.com...
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

Jul 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
2700
by: Sergio del Amo | last post by:
Hi, I use the xslt functions provided by php. I am running in my computer the package xampp(www.apachefriends.org) which includes php/apache/mysql .. In this package the php includes the sablotron extension responsible for the xslt functions. The problem i have is that the obtained transformation is not the waited one. I try to proccess the same XML file with XSL file with a program called XMLspy and i obtained the desire and waited...
3
7910
by: pradeep gummi | last post by:
I have an XML FILE that is to be converted to Plain Text using an XSL file. Since I just want plain text, I do not want to set any root element during transformation.And if I do not any root element during transformation, it return s "java.lang.IllegalStateException: Root element not set" exception. If I add any element for the enclosed root, it works. Note: I am using XMLOutputter object of JDOM API, packages javax.xml.transform and...
4
4725
by: Mike Conmackie | last post by:
Hi Folks, I've probably omitted something very basic but I have no idea what it might be. The results of my transformation _should_ be an xml file but all I get is the xml declaration immediately followed by the input node text values in one long string -- no xml tags (barring the xml declaration, of course) appear in the output file. Anyone who wants to see either the input xml file or the xsl file, please let me know and I will...
1
1923
by: Andrew Connell | last post by:
I have an XML document and an XSLT transformation sheet. My first issue is that my XML file won't load into the XPathDocument object. However, when I use an obsolete transformation method where I specify the XML input file and output file, I get the same error. The error is: An unhandled exception of type 'System.Xml.XmlException' occurred in system.xml.dll Additional information: System error. Here's my code... commented to show where...
2
1785
by: TomekR | last post by:
Hello ! I was developing xslt sheet lately and - experimenting - I made mistake resulting in that, the effect of the transformation is not well-formed xml document. I made these tests using XmlSpy and in output window I can see two parallel elements - according to "logic" of me sheet. The error of that document is that it doesn't have root element. Here is the contents of XmlSpy output window:
7
1488
by: Bilal | last post by:
Hello, I'm attempting to "populate" an template XML file with some data using identity transform (approach suggested by Joe K.; Thanks! :-) and have come across some strange behaviour using XMLSpy, AltovaXML, and xsltproc. The actual stylesheets are to be auto-generated by another stylesheet (that process I've worked out! :-) and now troubleshooting these generated stylesheets in XMLSpy's XSL debugger. So I'm wondering if my approach is...
2
1812
by: HendrikLeder | last post by:
Hello everybody :-) Next year I`ll write my diploma in computer science for business (It`s a degree in Germany) and I`ve some questions about the topic. The diploma will handle about refactoring of xml-schemes and a transformation of all instances (the xml-documents) with XSLT-scripts. The idea of the diploma is, that in nearly every company xml schemes are used. And (like Heraklit said "Panta rhei" - everthing is flowing) the business...
18
2749
by: R. P. | last post by:
I wonder how to indicate in a stylesheet that character entities in an element are not to be transformed as would be the case in XML-to-XML transforms. I want to keep those &amp; &quot; and other character entities in the output as they are in the input. My stylesheet converts them the '&' etc., making the output XML not formed properly. R.P
14
9098
by: Thomas Bauer | last post by:
Hello, I search a example like that. (1,0,0,1,4,5 ) -- moving (1,0,0,1,0,0 ) -- normal matrix (-1,0,0,1,0,0 ) -- Mirror Y-Axis (0,-1,0,1,0,0 ) -- Mirror X-Axis I caluculate all in mm.
2
2100
by: abhimanyu singh | last post by:
i m facing a serious probs now a days............ its seems easy but for me i found it difficult......... i want to do transformation usig xsl and xml(adding parameter). for IE its working fine but for other browser like-firefox,opera its not working......... i m giving u my complete xml,xsl and transformation code....u only paste and check why it is not working for other browser.....and correct it and let me know......this is really a big...
0
8403
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8316
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8833
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8509
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7345
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6174
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4168
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4327
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1730
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.