"Daniel Walzenbach" <da**********************@freudenberg.de> wrote in message
news:5C**********************************@microsof t.com...
I need to know how to transform a XML file by using a XSLT file. Consider the following XML file:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?><LogFile>
<Dog TimeStamp="16.02.2004 10:04:48" ModifiedBy="Smith,
Geoff"><NameOfDog>Fido</NameOfDog><Weight>10</Weight>
</Dog>
: : Modified by: Smith, Geoff (16.02.2004 10:04:48)
Daniel,
You'll have to set the xsl:output element to set an output method of text,
and then it's simply a matter of placing the results of several XPath
expressions at the desired places in a document.
For starters,
- - - DogLog.xsl (excerpt)
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text" />
<xsl:template match="LogFile/Dog">
<xsl:text>Modified by: </xsl:text>
<xsl:value-of select="@ModifiedBy" />
<xsl:text> (</xsl:text>
<xsl:value-of select="@TimeStamp" />
<xsl:text>)
</xsl:text>
</xsl:template>
<xsl:template match="/">
<xsl:apply-templates select="LogFile/Dog" />
</xsl:template>
</xsl:stylesheet>
- - -
With text output, settings for whitespace preservation may conflict with
natural and clear indenting of XSL source, so rather than just use a basic
literal text document with preserved whitespace, I use xsl:text elements
above to precisely distinguish the literal text content I want emitted into
the target document from the other whitespace that is only used to
present a readable stylesheet.
In these text elements, you see the two character entities, #x0d; and #x0a;
which correspond to the carriage return and line feed (ie, the character
codes you may be more familiar with from C languages as "\r\n") that intro-
duce a newline into the text output.
There are two template rules in this stylesheet. The first matches the root
node of the document (which in XPath-thinking, is the node containing the
document element, LogFile) and applies the second template (iteratively)
over each record wrapped by the Dog element.
The xsl:value-of elements are how the result of XPath expressions against
the source document get injected into the result document. From this basic
skeleton, you should be able to extend it further to create text reports
formatted however you like.
Derek Harmon