开发者

XSLT: keeping whitespaces when copying attributes

开发者 https://www.devze.com 2023-03-02 13:03 出处:网络
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, i

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>


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号