xml – XSLT删除所有属性的前导和尾随空格

前端之家收集整理的这篇文章主要介绍了xml – XSLT删除所有属性的前导和尾随空格前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
如何创建相同的 XML表单,但每个属性的前导和尾随空格都被删除? (使用XSLT 2.0) @H_403_1@从此开始:

<node id="DSN ">
    <event id=" 2190 ">
        <attribute key=" Teardown"/>
        <attribute key="Resource "/>
    </event>
</node>
@H_403_1@为此:

<node id="DSN">
    <event id="2190">
        <attribute key="Teardown"/>
        <attribute key="Resource"/>
    </event>
</node>
@H_403_1@我想我更喜欢使用normalize-space()函数,但无论如何.

normalize-space()不仅可以删除前导和尾随空格,还可以安装单个空格字符来代替连续空格字符的任何序列. @H_403_1@正则表达式可用于处理前导和尾随空格:

<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>
原文链接:https://www.f2er.com/xml/292178.html

猜你在找的XML相关文章