xml – XSLT删除所有属性的前导和尾随空格
发布时间:2020-12-16 07:41:43 所属栏目:百科 来源:网络整理
导读:如何创建相同的 XML表单,但每个属性的前导和尾随空格都被删除? (使用XSLT 2.0) 从此开始: node id="DSN " event id=" 2190 " attribute key=" Teardown"/ attribute key="Resource "/ /event/node 为此: node id="DSN" event id="2190" attribute key="Te
|
如何创建相同的
XML表单,但每个属性的前导和尾随空格都被删除? (使用XSLT 2.0)
从此开始: <node id="DSN ">
<event id=" 2190 ">
<attribute key=" Teardown"/>
<attribute key="Resource "/>
</event>
</node>
为此: <node id="DSN">
<event id="2190">
<attribute key="Teardown"/>
<attribute key="Resource"/>
</event>
</node>
我想我更喜欢使用normalize-space()函数,但无论如何.
normalize-space()不仅可以删除前导和尾随空格,还可以安装单个空格字符来代替连续空格字符的任何序列.
正则表达式可用于处理前导和尾随空格: <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:template match="node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="@*">
<xsl:attribute name="{local-name()}" namespace="{namespace-uri()}">
<xsl:value-of select="replace(.,'^s+|s+$','')"/>
</xsl:attribute>
</xsl:template>
</xsl:stylesheet>
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
