XSLT transformation to remove space within element

前端 未结 2 550
执笔经年
执笔经年 2021-01-25 11:20

I am a bit new to XSLT stuff. The problem is that I need to get rid of whitespaces within certain elements in my input XML. For example



        
相关标签:
2条回答
  • 2021-01-25 11:32

    Hope, this will help you.

    <xsl:template match="text()">
        <xsl:value-of select="fn:normalize-space()"/> <!-- fn is the prefix bound to xpath functions -->
    </xsl:template>
    
    0 讨论(0)
  • 2021-01-25 11:35

    What you like to do is an Identity transform.

    Try something like this:

    <?xml version="1.0" encoding="utf-8" ?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
        <xsl:output method="xml" indent="yes"/>
        <xsl:strip-space elements="*"/>
    
        <xsl:template match="@* | node()">
            <xsl:copy>
                <xsl:apply-templates select="@* | node()"/>
            </xsl:copy>
        </xsl:template>
    
        <xsl:template match="text()">
            <xsl:value-of select="normalize-space()"/>
        </xsl:template>
    
    </xsl:stylesheet>
    
    0 讨论(0)
提交回复
热议问题