XSL output method text, including spaces in xsl

I am creating some xsl to convert my xml to text (which will eventually be csv). I am using VS2008. When I use the editor to create xsl, the converted output is indented according to my xsl. However, if I edit xsl and remove the formatted spaces, it displays correctly, but to do it as if it were a nightmare to work with.

Are there some xsl pre-processor commands or markup that I can enable to prevent this? I want to ignore any spaces in my xsl and only output text with <!CDATA[]]>or <xsl:text>.

My XSL looks like this: it's indented output

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl"
>
  <xsl:output method="text" indent="no"/>
  <!-- @* is all class attributes -->
  <xsl:template match="/">
    <xsl:text>CSV Output</xsl:text>
    <!-- Start of output -->
    <xsl:for-each select="//rows/row">
      <![CDATA[row id=]]><xsl:value-of select="(@id)"/>
    </xsl:for-each>
    <!-- OK, that is the end of the file -->
    <![CDATA[<EOF>]]>
  </xsl:template>
</xsl:stylesheet>

The result of this is as follows:

CSV Output
      row id=0
      row id=1
    <EOF>

However, the following outputs are correct:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl"
>
  <xsl:output method="text" indent="no"/>
  <!-- @* is all class attributes -->
  <xsl:template match="/">
    <xsl:text>CSV Output</xsl:text>
    <!-- Start of output -->
    <xsl:for-each select="//rows/row">
<![CDATA[row id=]]><xsl:value-of select="(@id)"/>
</xsl:for-each>
<!-- OK, that is the end of the file -->
<![CDATA[<EOF>]]>
  </xsl:template>
</xsl:stylesheet>

This is correctly displayed as follows:

CSV Output
row id=0
row id=1
<EOF>

, . xsl , .

, !

,

Andez

+3
2

XSLT XSLT.

,

<xsl:for-each select="//rows/row"> 
  <![CDATA[row id=]]><xsl:value-of select="(@id)"/> 
</xsl:for-each>

xsl:for-each : xsl:value-of, ; CDATA, .

: xsl:text.

<xsl:for-each select="//rows/row"> 
  <xsl:text><![CDATA[row id=]]></xsl:text>
  <xsl:value-of select="@id"/> 
</xsl:for-each>
+5

xsl:strip, , ( * ):

<xsl:strip-space elements="*"/>

xsl:preserve, , . :

<xsl:strip-space elements="*"/>
<xsl:preserve-space elements="td span"/>
<!-- strip spaces from all elements apart from td and span elements -->
+5

Source: https://habr.com/ru/post/1767538/


All Articles