I am creating a Xsl file programmatically with a XmlDocument object. I save
the document with XmlDocument(string Path).
All Nodes added to the document root are idented nicely. But any child nodes
to them are just written in the same line. Is there a possibility to modify
the saving? The hierarchy is correctly written - data-wise.
Example (incorrect version, see all the Children of "PropA" in a row instead
with newlines and tabs):
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text" />
<xsl:template match="PropA">val1: <xsl:value-of select="val1" />val2:
<xsl:value-of select="val2" /></xsl:template>
</xsl:stylesheet>
correct version:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text" />
<xsl:template match="PropA">
val1: <xsl:value-of select="val1"/>
val2: <xsl:value-of select="val2"/>
</xsl:template>
</xsl:stylesheet>
Thx in advance for your help,
Fabian
> Example (incorrect version, see all the Children of "PropA" in a row instead
> with newlines and tabs):
[quoted text clipped - 18 lines]
> </xsl:template>
> </xsl:stylesheet>
The element has mixed contents (text children and element children) and
indenting that could change the semantics respectively it is not
necessarily clear how to indent that. You want the above format but
<xsl:template match="PropA">
val1:
<xsl:value-of select="val1"/>
...
</xsl:template>
is also possible.
So you will need to write your own XmlWriter that performs the
indentation you are looking for.
Or alternatively, as you are creating an XSLT stylesheet, you could wrap
the text in xsl:text e.g.
<xsl:text>val1: </xsl:text>
then the xsl:template no longer has mixed contents and the child
elements would be indented as e.g.
<xsl:template match="PropA">
<xsl:text>val1: </xsl:text>
<xsl:value-of select="val1"/>
...
</xsl:template>

Signature
Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Fabian - 20 Feb 2008 13:51 GMT
> Or alternatively, as you are creating an XSLT stylesheet, you could wrap
the text in xsl:text
This works but is not yet all I need: Can I influence the idendation?
Instead of
<xsl:template match="PropA">
<xsl:text>val1: </xsl:text>
<xsl:value-of select="val1"/>
</xsl:template>
I would like to have
<xsl:template match="PropA">
<xsl:text>val1: </xsl:text> <xsl:value-of select="val1"/>
</xsl:template>
i.e. no line feed between the text node and the value. Is this somehow
possible? I know I can probably also make the output look like this with some
forward looking XPath query but this is probably not the easiest way, I
think.
Thx,
Fabian
Martin Honnen - 20 Feb 2008 14:05 GMT
> This works but is not yet all I need: Can I influence the idendation?
> Instead of
[quoted text clipped - 14 lines]
> forward looking XPath query but this is probably not the easiest way, I
> think.
As said, if you implement your own XmlWriter that does the indentation
you want then you can pass that to the Save method of an XmlDocument
instance. Or, as you are already using XmlDocument to create the XSLT
stylesheet, you can use PreserveWhitespace = true and then insert text
nodes as needed. I don't think there is anything in the .NET framework
that does what you want out of the box.

Signature
Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/