Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
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 April 28th, 2008, 11:58 AM
Registered User
 
Join Date: Apr 2008
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default for-each carriage returns

I am having trouble with a for-each loop adding a carriage return after each iteration. Is this the default behavior for for-each loops? Can it be avoided? I am creating a PDF from the transform and I do not want line breaks between each anchor tag.

XSL
Code:
<xsl:for-each select="key('indexlist', text())">
    <xsl:element name="a">
        <xsl:attribute name="href">#indexterm-<xsl:number level="any"/></xsl:attribute><xsl:text />
    </xsl:element>
</xsl:for-each>
OUTPUT
Code:
<a href="#indexterm-1"/>
<a href="#indexterm-2"/>
<a href="#indexterm-3"/>
<a href="#indexterm-4"/>
<a href="#indexterm-5"/>
What I would like to see
Code:
<a href="#indexterm-1"/><a href="#indexterm-2"/><a href="#indexterm-3"/><a href="#indexterm-4"/><a href="#indexterm-5"/>
 
Old April 28th, 2008, 12:15 PM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

There are alternatives but the simplest would appear to be:[code<xsl:for-each select="key('indexlist', text())">
    <xsl:element name="a">
        <xsl:attribute name="href">#indexterm-<xsl:number level="any"/></xsl:attribute</xsl:element></xsl:for-each>[/code]

--

Joe (Microsoft MVP - XML)
 
Old April 28th, 2008, 12:24 PM
Registered User
 
Join Date: Apr 2008
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Putting them all on the same line gives the same output.
 
Old April 28th, 2008, 12:27 PM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

Try at the top level looking for an <xsl:output> instruction.

If one does exist then add one like the following:

<xsl:stylesheet ...>
<xsl:output indent="no"/>
...

/- Sam Judson : Wrox Technical Editor -/
 
Old April 28th, 2008, 07:31 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

The only reason I can think of why you would get newlines here is if you have specified <xsl:output indent="yes"/>. If you have, change it.

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
display carriage returns in label bleitner ASP.NET 2.0 Professional 4 May 21st, 2011 12:10 PM
insert carriage return darkhalf Javascript 0 April 10th, 2007 02:42 PM
How are Carriage Returns stored? SQLScott SQL Server 2005 2 December 1st, 2006 04:07 PM
How are Carriage Returns stored? SQLScott SQL Server 2000 3 November 24th, 2006 10:37 AM
about carriage return... edu1980 XSLT 1 July 5th, 2006 04:11 AM





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