Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
| Search | Today's Posts | Mark Forums Read
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 25th, 2005, 05:38 PM
Authorized User
 
Join Date: Sep 2004
Location: , , .
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
Default xsl:element not on its own line in output

I'm doing an xml to xml transformation. For some reason, certain elements that I create are not being placed on their own line in the output.

Here's a piece of the stylesheet - the template of one of the elements that's having problems.

<xsl:output method="xml" indent="no" />

<xsl:template match="ItemSet">
    <xsl:element name="instruction">
    <xsl:if test="Directions/PointValue">
        <xsl:element name="points_section">
            <xsl:apply-templates />
        </xsl:element>
    </xsl:if>
    <xsl:if test="not(Directions/PointValue)">
        <xsl:apply-templates />
    </xsl:if>
    </xsl:element>
</xsl:template>

The output *should* look like this:


<instruction>
    <Title>Part 2: Essay</Title>
    Answer the following question on the back of this paper or on a separate sheet.
    <ItemGuid>act0976d97b8006be86_139</ItemGuid>
    <qe>How were Egyptian ideas about the afterlife reflected in their treatment of the dead?</qe>
    <a>The Egyptians believed they would have a happy afterlife, and that they would need both their bodies and objects from their lives.</a>
</instruction>

This is what I *am* getting:

<instruction><Title>Part 2: Essay</Title>Answer the following question on the back of this paper or on a separate sheet.<ItemGuid>act0976d97b8006be86_139</ItemGuid>
<qe>How were Egyptian ideas about the afterlife reflected in their treatment of the dead?</qe>
<a>The Egyptians believed they would have a happy afterlife, and that they would need both their bodies and objects from their lives.</a></instruction>

The <qe> and <a> elements are falling correctly on their own lines, but nothing I do (I've tried using <xsl:text>#xA;</xsl:text>, <xsl:text>#&13;</xsl:text> and <xsl:text>#x0D;</xsl:text> to no avail) will make the <instruction> element (and several others) fall on new lines.

I've also tried changing the output method line to be indent="yes", which fixes the issue for some tags, but not others.

The files are being processed in Epic Editor (compose using XSL), which ArborText tells me is built on Saxon. Any ideas?


 
Old February 25th, 2005, 06:59 PM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Not enough information to give the answer here. You haven't said why you think there should be more whitespace in the result tree than there is.

Whitespace in the result tree comes from one of three places: from nodes copied from the source document, from text written by the stylesheet, and from use of indent="yes". Your stylesheet uses indent="no", and from what you've shown us doesn't generate any whitespace text nodes. You haven't shown us the input, so we can't see what's being copied from there.

indent="yes" will never generate whitespace adjacent to existing text. If you want newlines before and after "Answer the following question" then they must either be in the original source, or your stylesheet must add them.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old February 25th, 2005, 09:33 PM
Authorized User
 
Join Date: Sep 2004
Location: , , .
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Adding new lines was what I was trying to do with any of these:

<xsl:text>#xA;</xsl:text>, <xsl:text>#&13;</xsl:text> and <xsl:text>#x0D;</xsl:text>

I had put them after the closing </element> tag, trying to ensure that there would be a line break after each element. But none of them worked.

 
Old February 26th, 2005, 06:08 AM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

You need to construct a cut down example and post the whole example: source document, stylesheet, and output. I can't help you solve the problem by guessing what's in the bits you haven't shown us or the other things that you tried.

Since you're using a development environment rather than just the raw XSLT processor, it would be as well to check that the serialization is actually being done by the XSLT processor. Sometimes tools like this send the output to a DOM and then serialize it themselves. The best way to do that is to try running it directly from the command line.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference




Similar Threads
Thread Thread Starter Forum Replies Last Post
remove duplicate text in an output html element mrame XSLT 1 June 20th, 2008 01:41 AM
XSL(T) problems with xsl:element pan69 XSLT 3 December 13th, 2007 06:24 AM
Transform multilined element value to one line ypomonh XSLT 2 April 27th, 2007 08:32 AM
Copy source-element to output tree der_bAUer XSLT 2 June 9th, 2006 08:17 AM
Can display output as Element name HareshVani XSLT 2 March 22nd, 2006 03:19 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.