XSLT 转换以删除元素内的空间 [英] XSLT transformation to remove space within element

查看:21
本文介绍了XSLT 转换以删除元素内的空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对 XSLT 的东西有点陌生.问题是我需要去掉输入 XML 中某些元素中的空格.例如

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

<element id="12">


</element>

应该变成

<element id="12"></element>

还有

<element id="12">

something

</element>

进入

<element id="12">something</element>

其余的 xml 应该保持不变.xsl 可以进行这种转换吗?

and the rest of the xml should remain the same. Is this kind of transformation possible with xsl?

推荐答案

你喜欢做的是一个 身份转换.

尝试这样的事情:

<?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>

这篇关于XSLT 转换以删除元素内的空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆