[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: adding space in xslt and trimming last space in ja

Subject: Re: adding space in xslt and trimming last space in java-problem
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Wed, 16 Jul 2003 16:18:59 -0400
space in xslt
Remko:

At 03:57 PM 7/16/2003, you wrote:
I have an XML-file that contains a sequence of ids. I need to transform this to a String of space separated ids.
So I transform the xml to a text file and after each id-node I add a space, like this:


<xsl:template match="*">
   <xsl:for-each select="//ns1:genbankid">
       <xsl:value-of select="text()"/>&#xa0;</xsl:for-each>
</xsl:template>

but when I try to trim the space of the lastly added id, it refuses to do it! My application is in Java:

ids.trim()

does not work.

This is rather extravagantly hopeful ain't it? (Do you try XSLT in your Java, too? :-)


In any case, if you want a space after every value but the last, try something like

<xsl:for-each select="//nsl:genbankid">
  <xsl:value-of select="."/>
  <xsl:if test="not(position() = last())">&#xa0;</xsl:if>
</xsl:for-each>

Any suggestions?? In VIM the transformed file shows not a space but a capital A with a ^ on top, I assume this is the problem.

Nope: it's a red herring. You are seeing this because VIM does not support the encoding of your output (probably UTF-8). Use an editor that does, to get a better view of what's actually in your file; or change how your output is being serialized (on the xsl:output top-level element) to an encoding that your toolset supports.


what can I use instead of &#xa0;??

You could use a plain space instead of the non-breaking one:


<xsl:if test="not(position() = last())">
  <xsl:text> </xsl:text>
</xsl:if>

assuming you don't mind that they break, of course.

Cheers,
Wendell


====================================================================== Wendell Piez mailto:wapiez@xxxxxxxxxxxxxxxx Mulberry Technologies, Inc. http://www.mulberrytech.com 17 West Jefferson Street Direct Phone: 301/315-9635 Suite 207 Phone: 301/315-9631 Rockville, MD 20850 Fax: 301/315-8285 ---------------------------------------------------------------------- Mulberry Technologies: A Consultancy Specializing in SGML and XML ======================================================================


XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list



Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.