我正在尝试对 Microsoft Visual Studio 的 vcproj 进行排序,以便在从项目中删除文件后,差异会显示一些有意义的内容。除了排序之外,我想保持所有内容完整,包括空格。输入看起来像
space
spacespaceRelativePath="filename"
spacespace >
...
下面的 xslt 片段可以在元素周围添加空格,但我不知道如何处理属性周围的空格,所以我的输出看起来像
space<代码><文件relativePath="filename">
xslt 我用于 msxsl 4.0 处理器:
>
I'm trying to sort Microsoft Visual Studio's vcproj so that a diff would show something meaningful after e.g. deleting a file from a project. Besides the sorting, I want to keep everything intact, including whitespaces. The input looks like
space<File
spacespaceRelativePath="filename"
spacespace>
...
The xslt fragment below can add the spaces around elements, but I can't find out how to deal with those around attributes, so my output looks like
space<File RelativePath="filename">
xslt I use for the msxsl 4.0 processor:
<xsl:for-each select="File">
<xsl:sort select="@RelativePath"/>
<xsl:value-of select="preceding-sibling::text()[1]"/>
<xsl:copy>
<xsl:for-each select="text()|@*">
<xsl:copy/>
</xsl:for-each>
发布评论
评论(2)
这些空格在 XML 中总是是微不足道的,而且我相信对于任何 XML/XSLT 库都没有办法以通用方式控制这种行为。
Those spaces are always insignificant in XML, and I believe that there is no option to control this behavior in a general way for any XML/XSLT library.
XSLT 使用输入 XML 的树表示形式。原始 XML 的许多不相关细节已在这棵树中被抽象出来 - 例如属性的顺序、属性之间无关紧要的空白,或者作为属性分隔符的“和 ' 之间的区别。我看不出有任何可以想象的理由想要编写一个将这些区别视为重要的程序。
XSLT works on a tree representation of the input XML. Many of the irrelevant detail of the original XML has been abstracted away in this tree - for example the order of attributes, insignificant whitespace between attributes, or the distinction between " and ' as an attribute delimiter. I can't see any conceivable reason for wanting to write a program that treats these distinctions as significant.