1

I've been trying to replace all space characters that occur in the schemaLocation attribute with newline characters. I've found many variations on how to do this. The simplest one is something like

    <xsl:variable name='nl'><xsl:text>
</xsl:text></xsl:variable>

and then in my replace,

<xsl:value-of select(replace($data,' ',$nl) />

however, every which way i try this, it prints the literal '#x0A;' in the file

I've tried updating XSL:OUTPUT to method="text" however this produces many other strange results

I simply want a newline to appear, not the "#x0A;" string representation of this

Beta033
  • 1,975
  • 9
  • 35
  • 48

1 Answers1

3

Hmm, from what you posted I'm not exactly sure what you did wrong. When you typed the newline in hex, did you forget the ampersand? A simple mistake. And from a design point of view, I suggest using the hex code for the newline since it is cleaner and difficult to accidentally delete.

This code works:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text"/>

<xsl:variable name="newline">
  <xsl:text>&#xa;</xsl:text>
</xsl:variable>

<xsl:template match="/">
  <xsl:variable name="data">
    <xsl:text>This is a string</xsl:text>
  </xsl:variable>
  <xsl:value-of select="replace($data,' ', $newline)" />
</xsl:template>

</xsl:stylesheet>

The output is exactly what we expect:

This
is
a
string
ljdelight
  • 486
  • 4
  • 13
  • 1
    If your goal is to put newlines IN attributes, read this: http://stackoverflow.com/questions/2004386/how-to-save-newlines-in-xml-attribute – ljdelight Mar 01 '13 at 02:58