Answer the question
In order to leave comments, you need to log in
How to remove spaces in XML using XSLT?
There is this XML:
<?xml version="1.0" encoding="UTF-8"?>
<content>
<p>Lorem ipsum dolor sit amet,</p>
<p>Quibusdam dolore iure deleniti quasi accusantium non nostrum facere neque ducimus
mollitia et ex suscipit, placeat, eius maiores ratione cumque. <b>Provident</b> doloribus
natus perspiciatis quas id sequi neque, molestiae cupiditate facere quod. Dolore voluptate
consectetur:</p>
<p>aperiam nihil.</p>
<dialog>
aperiam nihil.
aperiam <b>123</b> nihil.
aperiam nihil.
<b>123</b>
</dialog>
<img src="images/my-image.jpg"/>
</content>
<xsl:template match="dialog">
<p class="dialog">
<xsl:copy-of select="node()"/>
</p>
</xsl:template>
Answer the question
In order to leave comments, you need to log in
Muhammad I correctly understood - "deleting extra spaces"?
beautiful and "little code" will not work - the replace function with regexp support is available only for version >=2.0.
For version 1.0, the only suitable solution for the task will be:
<xsl:stylesheet version="1.1"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="p">
<xsl:copy-of select="."/>
</xsl:template>
<xsl:template match="dialog">
<p class="dialog">
<xsl:for-each select="./*|./text()">
<xsl:choose>
<xsl:when test="self::text()">
<xsl:value-of select="normalize-space(.)" />
</xsl:when>
<xsl:otherwise>
<xsl:text> </xsl:text>
<xsl:copy>
<xsl:copy-of select="./text()"/>
</xsl:copy>
<xsl:text> </xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</p>
</xsl:template>
</xsl:stylesheet>
<?xml version="1.0"?>
<p>Lorem ipsum dolor sit amet,</p>
<p>Quibusdam dolore iure deleniti quasi accusantium non nostrum facere neque ducimus
mollitia et ex suscipit, placeat, eius maiores ratione cumque. <b>Provident</b> doloribus
natus perspiciatis quas id sequi neque, molestiae cupiditate facere quod. Dolore voluptate
consectetur:</p>
<p>aperiam nihil.</p>
<p class="dialog">aperiam nihil. aperiam <b>123</b> nihil. aperiam nihil. <b>123</b> </p>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question