2

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 Answers2

1

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.

Lucero
  • 59,176
  • 9
  • 122
  • 152
1

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.

Michael Kay
  • 156,231
  • 11
  • 92
  • 164
  • I would say that not even an **XML parser** do care about attributes order or space between as per the specs. –  May 01 '11 at 02:30