XSLT disable-output-escaping="yes" without line break

I need to make XSLT which will generete json.

The problem is that i have &lt; and &gt; symbols in my xml which need to be replaced with <> in output. But disable-output-escaping="yes" makes line break, can i remove this line break?

XML:

<item id="166" group="0">
<name>Some Titile</name>
<text>&lt;p&gt;A dizzying array of deep, robust color, the Hugs and Kisses bouquet contains one dozen tulips and one dozen iris, fresh from the fields. It's an always-impressive bouquet perfect for a &quot;dinner for two,&quot; a special someone's birthday, or anytime you want to make someone's heart race.&lt;/p&gt;</text>
</item>

Output which I need

{
    "name": "Some Title",
    "text": "<p>A dizzying array of deep, robust color, the Hugs and Kisses bouquet contains one dozen tulips and one dozen iris, fresh from the fields. It's an always-impressive bouquet perfect for a &quot;dinner for two,&quot; a special someone's birthday, or anytime you want to make someone's heart race.</p>;"
}

XSLT

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

  <xsl:template match="item">
    {
    "name": "<xsl:value-of select="name" />",
    "text": "<xsl:value-of select="text" />"
    }
  </xsl:template>
</xsl:stylesheet>

Output

{
    "name": "Some Title",
    "text": "&lt;p&gt;A dizzying array of deep, robust color, the Hugs and Kisses bouquet contains one dozen tulips and one dozen iris, fresh from the fields. It's an always-impressive bouquet perfect for a &quot;dinner for two,&quot; a special someone's birthday, or anytime you want to make someone's heart race&lt;./p&gt;;"
}

Answers


Well if you want to generate Javascript code respectively JSON code then simply use <xsl:output method="text"/>, that way no characters in the tranformation result will be escaped and there certainly then is no need to use disable-output-escaping.

On the other hand I don't see why disable-output-escaping should yield line breaks so if you still have problems consider to show us the details like the XML input, the XSLT code, the result you want and the one you get, and which XSLT processor you use.


If you are generating JSON, don't use disable-output-escaping, use the text output method:

<xsl:output method="text"/>

With the text output method, there is no escaping, therefore no need to disable it.

I don't know if this solves the problem with newlines, since I don't know what's causing that problem.


Need Your Help

Safari View Controller customizing size, frame add as a subview

ios9 sfsafariviewcontroller

How can I customize Safari View Controller to have my navigation bar and my navigation bar button to be seeing on the screen? Is this possible to do?

Haskell: Stack overflow when finding max on a large list

performance haskell stack-overflow lazy-evaluation

I have the following implementation of problem 1-4 of the Matasano Cryptopals Challenge, to find one line in a file that is a text string xor'd with a single byte. It works well enough for large fi...