Remove newline character/white space from xml using xslt or xquery transformation

StackOverflow https://stackoverflow.com/questions/22803218

  •  26-06-2023
  •  | 
  •  

문제

How to remove newline character/white space from xml using xslt or xquery transformation.Means all the elements will come in a single line.

도움이 되었습니까?

해결책

In xslt, you can add a top level element

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

By using a sample input XML below:

<?xml version="1.0" encoding="utf-8"?>
<root>
    <a>XXX</a>
    <b>YYY</b>
    <c>ZZZ</c>
</root>

and the following XSLT:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:strip-space elements="*"/>

    <!-- this is called an identity template -->
    <xsl:template match="node()|@*">
        <xsl:copy>
            <xsl:apply-templates select="node()|@*"/>
        </xsl:copy>
    </xsl:template>

</xsl:stylesheet>

produces:

<?xml version="1.0" encoding="utf-8"?><root><a>XXX</a><b>YYY</b><c>ZZZ</c></root>
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top