如何在XSLT中的元素的开始标记内保留空格 [英] How to preserve whitespace within an element's opening tag in XSLT

查看:135
本文介绍了如何在XSLT中的元素的开始标记内保留空格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为了避免将敏感信息提交到SCM存储库,我编写了一个XSL样式表,该样式表从ASP.NET Web.config文件中删除了连接字符串密码.它达到了删除密码的目的,但同时也影响了元素开头标签内的空格.如果可能的话,我想保留这个空白.

In order to avoid committing sensitive information to an SCM repository, I wrote an XSL stylesheet that removes connection string passwords from ASP.NET Web.config files. It achieves my goal of removing passwords, but it also affects the whitespace within the opening tags of elements. I would like to preserve this whitespace if possible.

例如,给定以下Web.config:

<configuration>
  <connectionStrings>
    <add name="ApplicationServices"
         connectionString="Host=localhost;Username=dev;Password='sensitive password';Database=database"
         providerName="MySql.Data.MySqlClient" />
  </connectionStrings>
  <!-- ... -->

我能够将其转换为:

<configuration>
  <connectionStrings>
    <add name="ApplicationServices" connectionString="Host=localhost;Username=dev;Password=********;Database=database" providerName="MySql.Data.MySqlClient" />
  </connectionStrings>
  <!-- ... -->

但是我想将其转换为:

<configuration>
  <connectionStrings>
    <add name="ApplicationServices"
         connectionString="Host=localhost;Username=dev;Password=********;Database=database"
         providerName="MySql.Data.MySqlClient" />
  </connectionStrings>
  <!-- ... -->

这可能吗?

推荐答案

空格并不重要,可以由处理器将其标准化为单个空格,您不能在标准工具中对此进行控制.您也无法控制用于引用的属性或字符的顺序("quots"与"apos").字符实体也可以转换为等效表示.有可能您会找到所需的自定义序列化程序,但在XSLT中找不到.

whitespace within tags is not significant and can be normalised by the processor to single spaces and you cannot control this in standard tools. Nor can you control the order of attributes or the characters used for quoting (quot vs apos). Character entities may also be converted to equivalent representations. It is possible that you can find custom serializers that will do want you want but not in XSLT.

请注意,如果需要,可以部分保留元素内容中的空白(但我认为这不是您的要求的一部分).

Note that the whitespace within element content can be partially preserved if required (but I don't think this was part of your requirement).

另请参见:保留属性空白

并查看有关空格的非常广泛的XSLT常见问题解答: http://www .dpawson.co.uk/xsl/sect2/N8321.html

And see the very extensive XSLT FAQ on whitespace: http://www.dpawson.co.uk/xsl/sect2/N8321.html

这篇关于如何在XSLT中的元素的开始标记内保留空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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