473,706 Members | 2,371 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

unwanted blank lines in output when using xalan

Hello everyone

I am transforming an XML document to text, basically only outputting
a small portion of it. When I run the following XSLT via Xalan's
processor,
I get a bunch of unwanted blank lines in the output.
Here is a simplified XML and XSLT:
(Note the problem does not happen when testing in XMLSpy)

- - - - - - - - - - - - - - - - - - - - - - - -
....
<AAA>
<anne anneId="blah" annName="blah"/>
<anne anneId="blah" annName="blah"/>
</AAA>
<BBB>
junk
</BBB>
<CCC>
junk
</CCC>
....
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - -
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE stylesheet [
<!ENTITY cr "<xsl:text>
</xsl:text>">
]>

<xsl:styleshe et version="2.0"
xmlns:xsl="http ://www.w3.org/1999/XSL/Transform">

<xsl:output method="text" version="1.0" encoding="UTF-8" />

<xsl:template match="/AAA/anne">
&cr;
<xsl:value-of select="@anneId "/> <xsl:text> </xsl:text>
<xsl:value-of select="@anneNa me"/>
</xsl:template>
</xsl:stylesheet>

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - -

I end up with a vast segment of blank lines before and after my data.
It is as if every time the processor reads any element, it's default
behaviour is to output a blank line, and when it actually matches with
the elements I want, then it behaves fine. If I put in "do nothing"
matches for all the other top level elements, then the number of blank
lines
is cut down, but not entirely eliminated:

<xsl:template match="/BBB"></xsl:template>
<xsl:template match="/CCC"></xsl:template>

NOTE: The "cr" entity is necessary to put *desired* blank lines between
my
lines of output data, and it shouldn't be triggered unless I match on
/AAA/anne right?

Does anyone know why I get these blanks, and how I can totally
eliminate them?

thanks,
Jeff

Feb 7 '06 #1
3 3702
Remember, whitespace in the source document is a legitimate part of the
document!

Your stylesheet provides an explicit rule for template for the AAA/anne
nodes... but it doesn't provide a template for the root element
(match="/"), which is where processing starts. That means your
stylesheet starts by applying the built-in default templates:

<xsl:template match="*|/">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="text()|@ *">
<xsl:value-of select="."/>
</xsl:template>

So, given your input document:

<doc>
<AAA>
<anne anneId="blah" annName="blah"/>
<anne anneId="blah" annName="blah"/>
</AAA>
<BBB>
junk
</BBB>
<CCC>
junk
</CCC>
</doc>

We first match the root node as "/". The built-in template processes
this by running apply-templates against its the children.

That takes us to <doc>. It matches as "*", so we do another level of
apply-templates against the children.

The first child of <doc> is the whitespace text node between <doc> and
<AAA>. This matches as text(), and we output its value -- a newline.

The next child is <AAA>. That matches as "*", so we start applying
templates to its content.

The next child is whitespace again -- between <AAA> and <anne> -- so we
output it. That's another blank line.

And so on. Basically, because you're letting the defaults run, you're
going to get most of the text content of the source document, including
all its newlines.

The best fix is to write your own match="/" template which takes you
more directly to what you want to process. If all you care about is
those <anne> elements, I'd suggest you try adding this to override the
builtin default and take you right to the nodes you want to see:

<xsl:template match="/">
<xsl:apply-templates select="/AAA/anne">
</xsl:template>

By the way, note that your template for the <anne> elements can just say
match="anne". You only need to say "/AAA/anne" if you need to
distinguish these from <anne> elements that might be encountered
elsewhere in the document.
Feb 8 '06 #2

Joe Kesselman wrote:
Remember, whitespace in the source document is a legitimate part of the
document!
[snip]

Thanks, Joe! That was a very informative discussion, and the result
works
great!
<xsl:template match="/">
<xsl:apply-templates select="/AAA/anne">
</xsl:template>

By the way, note that your template for the <anne> elements can just say
match="anne". You only need to say "/AAA/anne" if you need to
distinguish these from <anne> elements that might be encountered
elsewhere in the document.


I couldn't get it to work if I just specified the final element "anne"
(I suppose I could
do "//anne", but anyway the full path works, and I had the idea that
doing it that way
saved the XSLT processor from having to search through the DOM tree...

--Jeff

Feb 8 '06 #3
>>By the way, note that your template for the <anne> elements can just say
match="anne ". You only need to say "/AAA/anne" if you need to
distinguish these from <anne> elements that might be encountered
elsewhere in the document.
.... I had the idea that doing it that way
saved the XSLT processor from having to search through the DOM tree...


Nope. If anything, you've added work, because now the processor has to
check that the <anne> element's parent is an <AAA>.

Select does the search. Match confirms that you've found the ones you're
interested in.
Feb 9 '06 #4

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

Similar topics

0
1941
by: Frank | last post by:
Hey all, I can't seem to get javascript running in my XSL document. <?xml version="1.0"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xmlns:xalan="http://xml.apache.org/xalan" xmlns:my-ext="ext1" extension-element-prefixes="my-ext"> <!--The component and its script are in the xalan namespace and define the
3
2009
by: Brynjar Glesnes | last post by:
Hi, I've browsed the Fop FAQ, usenet and the internet hoping to find a solution to my problem, but in vain. I am using Xerces 2.6.2, Xalan-J 2.6.0 and Fop 0.20-5 to create PDF-documents. In the rendered PDF there is an unwanted whitespace after each xsl:value-of. An example: What I want to render to "Doe, John" renders to "Doe ,
3
1937
by: johkar | last post by:
What is the proper doctype syntax for XHTML transitional??? Strict? How come XSLT doesn't preserve XHTML when it is compiled (Xalan)? Meaning, <br /> tags become <br> <input /> tags become <input> etc. It seems I am dazed and confused? Any hints or clear online resources appreciated. John
3
411
by: Buz | last post by:
I am having a problem with extra, unwanted space showing up on my web form tables. I've tried hand coding and can get the htm file to display fine. But as soon as I bring the form into Visual Studio, convert it to an aspx web form, and insert my user controls, I start getting extra blank space between my rows, even when I give an explicit "height" attribute. The problem seems to occur with tables that have rowspans and/or user...
3
8595
by: yanakal | last post by:
Hi, I'm using isql to query data and output the same to a flat file. The isql has the following command options ' -h-1 -w500 -n -b -s"" '. In the SQL_CODE, the first two lines before the select statement are use dbname set nocount on go When I run this, an additional blank line is put into the output file. Actually, there are two lines after the last result set in the output file. This file is being fed into another system and the...
5
1295
by: Elhanan | last post by:
hi.. i don't exactly how to calls this , but is there a property for xalan, to output xml with crarriage return? i'm trying out xslt and the output can't be read with a normal editor, i know when serliaze xml with java, you can place a parameter saying the xml string will be output in human readble form.
2
3993
by: Olveres | last post by:
Hi, I have managed to work out how to add new lines into a calculated text box. However in this text box some of the outcome fields are empty however when previewing the report it includes the blank fields, so each section of the report is the same size, my field is set to can grow/shrink, but I think my inclusion in the code for the calculated box of all 15 outcomes (I have no choice) is what's causing each calculated box to be the...
0
886
by: ShapeMan | last post by:
Hi there, I'm writing a log file using File.AppendText in C# like so: swLog.WriteLine(msg); The file is closed and re-opened when another result is ready to be logged. In the output file I get the following: <Blank line> msg
6
3727
by: John Larson | last post by:
Hi All, I am some information from INSPEC database records in XML to build a relational database of my own. I am currently trying to extract information by doing an XSLT transform of the XML files into a tab-separated text file that I want to import into the database. I have run into the following problem: in some documents there are missing elements, for instance the volume and issue number of an article is not there (i.e. it is defined...
0
8781
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
8696
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
9155
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9050
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,...
1
6614
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
5938
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4448
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
4709
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2094
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.