用于将空正文转换为 SUCCESS 消息的 XSLT

XSLT for converting empty body to a SUCCESS message

我正在尝试通过 XSLT 将成功的 DELETE 操作生成的空响应主体替换为 "Success" 消息。

任何人都可以帮助我使用 XSLT,如果响应正文为空,它可以简单地打印 SUCCESS 消息。

响应正文将是: <response status="204"> </response>

预期输出: <response status="204">SUCCESS</response>

评论更新:如果响应不为空,那么它应该打印与响应相同的内容。

目前正在使用以下 XSLT:

<xsl:stylesheet version="1.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output omit-xml-declaration="yes" indent="yes"/>
    <xsl:strip-space elements="*"/>

    <xsl:template match="node()|@*">
        <xsl:copy>
            <xsl:apply-templates select="node()|@*"/>
        </xsl:copy>
    </xsl:template>

    <xsl:template match="*[not(*) and not(normalize-space())]">
        <xsl:element name="{name()}" namespace="{namespace-uri()}"/>
    </xsl:template>
</xsl:stylesheet>

但它给出了: <response/> 作为输出。

Can anyone help me with the XSLT which can simply print a SUCCESS message, if the response body is empty.

If the response is not empty then it should print the same what comes back as a response.

然后尝试:

XSLT 1.0

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

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

<xsl:template match="/response[not(node())]">
    <xsl:copy>
        <xsl:apply-templates select="@*"/>
        <xsl:text>SUCCESS</xsl:text>
    </xsl:copy>
</xsl:template>

</xsl:stylesheet>