Here is an example I had around. My xml is "excel flavored", but you should
be able to pick up the points.
1. I start with a source xml called "start out" xml
2. I supply the xsl.
3. I apply the xsl to the xml.
4. It results in ~another xml file.
If this isn't what you're after, then you need to describe your issue a
little more in detail.
Good luck, I think this will help.
-------------------"START OUT" XML--------------------------------
<?xml version="1.0"?>
<?mso-application progid="Excel.Sheet"?>
<Workbook xmlns="urn:schemas-microsoft-com
![Blush :o :o](/styles/default/custom/smilies/blush.gif)
ffice:spreadsheet"
xmlns
![Blush :o :o](/styles/default/custom/smilies/blush.gif)
="urn:schemas-microsoft-com
![Blush :o :o](/styles/default/custom/smilies/blush.gif)
ffice
![Blush :o :o](/styles/default/custom/smilies/blush.gif)
ffice"
xmlns:x="urn:schemas-microsoft-com
![Blush :o :o](/styles/default/custom/smilies/blush.gif)
ffice:excel"
xmlns:ss="urn:schemas-microsoft-com
![Blush :o :o](/styles/default/custom/smilies/blush.gif)
ffice:spreadsheet"
xmlns:html="
http://www.w3.org/TR/REC-html40">
<DocumentProperties xmlns="urn:schemas-microsoft-com
![Blush :o :o](/styles/default/custom/smilies/blush.gif)
ffice
![Blush :o :o](/styles/default/custom/smilies/blush.gif)
ffice">
<Author>sholliday</Author>
<LastAuthor>name</LastAuthor>
<Created>2003-12-22T18:58:08Z</Created>
<LastSaved>2003-12-23T15:51:38Z</LastSaved>
<Company>organization</Company>
<Version>11.8107</Version>
</DocumentProperties>
<ExcelWorkbook xmlns="urn:schemas-microsoft-com
![Blush :o :o](/styles/default/custom/smilies/blush.gif)
ffice:excel">
<WindowHeight>8835</WindowHeight>
<WindowWidth>11340</WindowWidth>
<WindowTopX>480</WindowTopX>
<WindowTopY>120</WindowTopY>
<ProtectStructure>False</ProtectStructure>
<ProtectWindows>False</ProtectWindows>
</ExcelWorkbook>
<Styles>
<Style ss:ID="Default" ss:Name="Normal">
<Alignment ss:Vertical="Bottom"/>
<Borders/>
<Font/>
<Interior/>
<NumberFormat/>
<Protection/>
</Style>
</Styles>
<Worksheet ss:Name="Sheet1">
<Table ss:ExpandedColumnCount="8" ss:ExpandedRowCount="4"
x:FullColumns="1"
x:FullRows="1">
<Column ss:Index="2" ss:AutoFitWidth="0" ss:Width="78"/>
<Column ss:AutoFitWidth="0" ss:Width="71.25"/>
<Column ss:AutoFitWidth="0" ss:Width="72"/>
<Column ss:Index="6" ss:AutoFitWidth="0" ss:Width="54.75"/>
<Column ss:AutoFitWidth="0" ss:Width="60.75"/>
<Row>
<Cell><Data ss:Type="String">myuid</Data></Cell>
<Cell><Data ss:Type="String">mylastname</Data></Cell>
<Cell><Data ss:Type="String">myfirstname</Data></Cell>
<Cell><Data ss:Type="String">myaddress1</Data></Cell>
<Cell><Data ss:Type="String">mycity</Data></Cell>
<Cell><Data ss:Type="String">mystate</Data></Cell>
<Cell><Data ss:Type="String">myzip</Data></Cell>
<Cell><Data ss:Type="String">mygender</Data></Cell>
</Row>
<Row>
<Cell><Data ss:Type="Number">123</Data></Cell>
<Cell><Data ss:Type="String">smith</Data></Cell>
<Cell><Data ss:Type="String">john</Data></Cell>
<Cell><Data ss:Type="String">123 main</Data></Cell>
<Cell><Data ss:Type="String">charlotte</Data></Cell>
<Cell><Data ss:Type="String">nc</Data></Cell>
<Cell><Data ss:Type="Number">55555</Data></Cell>
<Cell><Data ss:Type="String">M</Data></Cell>
</Row>
<Row>
<Cell><Data ss:Type="Number">234</Data></Cell>
<Cell><Data ss:Type="String">jones</Data></Cell>
<Cell><Data ss:Type="String">mary</Data></Cell>
<Cell><Data ss:Type="String">543 hickory</Data></Cell>
<Cell><Data ss:Type="String">statesville</Data></Cell>
<Cell><Data ss:Type="String">nc</Data></Cell>
<Cell><Data ss:Type="Number">44444</Data></Cell>
<Cell><Data ss:Type="String">F</Data></Cell>
</Row>
<Row>
<Cell><Data ss:Type="Number">345</Data></Cell>
<Cell><Data ss:Type="String">moore</Data></Cell>
<Cell><Data ss:Type="String">pat</Data></Cell>
<Cell><Data ss:Type="String">342 sycamore</Data></Cell>
<Cell><Data ss:Type="String">asheville</Data></Cell>
<Cell><Data ss:Type="String">nc</Data></Cell>
<Cell><Data ss:Type="Number">33333</Data></Cell>
<Cell><Data ss:Type="String">U</Data></Cell>
</Row>
</Table>
<WorksheetOptions xmlns="urn:schemas-microsoft-com
![Blush :o :o](/styles/default/custom/smilies/blush.gif)
ffice:excel">
<Selected/>
<Panes>
<Pane>
<Number>3</Number>
<ActiveCol>1</ActiveCol>
</Pane>
</Panes>
<ProtectObjects>False</ProtectObjects>
<ProtectScenarios>False</ProtectScenarios>
</WorksheetOptions>
</Worksheet>
<Worksheet ss:Name="Sheet2">
<WorksheetOptions xmlns="urn:schemas-microsoft-com
![Blush :o :o](/styles/default/custom/smilies/blush.gif)
ffice:excel">
<ProtectObjects>False</ProtectObjects>
<ProtectScenarios>False</ProtectScenarios>
</WorksheetOptions>
</Worksheet>
<Worksheet ss:Name="Sheet3">
<WorksheetOptions xmlns="urn:schemas-microsoft-com
![Blush :o :o](/styles/default/custom/smilies/blush.gif)
ffice:excel">
<ProtectObjects>False</ProtectObjects>
<ProtectScenarios>False</ProtectScenarios>
</WorksheetOptions>
</Worksheet>
</Workbook>
---------------END----"START OUT" XML--------------------------------
-------- START XSL TO APPLY--------------------------
<xsl:stylesheet version="1.0"
xmlns:xsl="
http://www.w3.org/1999/XSL/Transform"
xmlns
![Blush :o :o](/styles/default/custom/smilies/blush.gif)
="urn:schemas-microsoft-com
![Blush :o :o](/styles/default/custom/smilies/blush.gif)
ffice
![Blush :o :o](/styles/default/custom/smilies/blush.gif)
ffice"
xmlns:x="urn:schemas-microsoft-com
![Blush :o :o](/styles/default/custom/smilies/blush.gif)
ffice:excel"
xmlns:ss="urn:schemas-microsoft-com
![Blush :o :o](/styles/default/custom/smilies/blush.gif)
ffice:spreadsheet" >
<xsl:template match="/">
<OneWellDefinedDS>
<!--<myRootPosition><xsl:value-of select="position()"/></myRootPosition>-->
<xsl:apply-templates select="ss:Workbook"/>
</OneWellDefinedDS>
</xsl:template>
<xsl:template match="ss:Workbook">
<!--<myWorkbookPosition><xsl:value-of
select="position()"/></myWorkbookPosition>-->
<xsl:apply-templates select="ss:Worksheet"/>
</xsl:template>
<xsl:template match="ss:Worksheet">
<!--<myWorksheetPosition><xsl:value-of
select="position()"/></myWorksheetPosition>-->
<xsl:choose>
<xsl:when test="position()=1">
<xsl:apply-templates select="ss:Table"/>
</xsl:when>
<xsl
![Blush :o :o](/styles/default/custom/smilies/blush.gif)
therwise>
</xsl
![Blush :o :o](/styles/default/custom/smilies/blush.gif)
therwise>
</xsl:choose>
</xsl:template>
<xsl:template match="ss:Table">
<!--<myTablePosition><xsl:value-of
select="position()"/></myTablePosition>-->
<xsl:apply-templates select="ss:Row"/>
</xsl:template>
<xsl:template match="ss:Row">
<!--<myRowPosition><xsl:value-of select="position()"/></myRowPosition>-->
<xsl:choose>
<xsl:when test="position()=1">
</xsl:when>
<xsl
![Blush :o :o](/styles/default/custom/smilies/blush.gif)
therwise>
<customerInfo>
<!--<myPosition><xsl:value-of select="position()"/></myPosition>-->
<xsl:apply-templates select="ss:Cell"/>
</customerInfo>
</xsl
![Blush :o :o](/styles/default/custom/smilies/blush.gif)
therwise>
</xsl:choose>
</xsl:template>
<xsl:template match="ss:Cell">
<!--<myCellPosition><xsl:value-of
select="$varCurrentAttributePosition"/></myCellPosition>-->
<xsl:choose>
<xsl:when test="position()=1">
<xsl:call-template name="xuid" />
</xsl:when>
<xsl:when test="position()=2">
<xsl:call-template name="xlastname" />
</xsl:when>
<xsl:when test="position()=3">
<xsl:call-template name="xfirstname" />
</xsl:when>
<xsl
![Blush :o :o](/styles/default/custom/smilies/blush.gif)
therwise>
</xsl
![Blush :o :o](/styles/default/custom/smilies/blush.gif)
therwise>
</xsl:choose>
</xsl:template>
<xsl:template name="xuid">
<uid><xsl:value-of select="."/></uid>
</xsl:template>
<xsl:template name="xlastname">
<lastname><xsl:value-of select="."/></lastname>
</xsl:template>
<xsl:template name="xfirstname">
<firstname><xsl:value-of select="."/></firstname>
</xsl:template>
</xsl:stylesheet>
-------- END XSL TO APPLY--------------------------
C# Code START (this will probably show as deprecated, but that's what I had
at the time.. alter as necessary)
public void DoTranslation(string xmlFile, string xslFile, string outputFile)
{
try
{
//Create a new XslTransform object.
XslTransform xslt = new XslTransform();
//Load the stylesheet.
xslt.Load(xslFile);
//Create a new XPathDocument and load the XML data to be transformed.
XPathDocument mydata = new XPathDocument(xmlFile);
//Create an XmlTextWriter which outputs to the console.
//XmlWriter writer = new XmlTextWriter(Console.Out);
//Transform the data and send the output to the console.
//xslt.Transform(mydata,null,writer, null);
xslt.Transform (xmlFile, outputFile);
}
catch (Exception ex)
{
debugMsg = ex.Message;
Console.WriteLine (debugMsg);
}
}
------------ Expected Result ( you shouldn't need this ... as the xsl
transformation above should create the xml below ,,, I put it here as a
reference )
<?xml version="1.0" encoding="utf-8" ?>
- <OneWellDefinedDS xmlns
![Blush :o :o](/styles/default/custom/smilies/blush.gif)
="urn:schemas-microsoft-com
![Blush :o :o](/styles/default/custom/smilies/blush.gif)
ffice
![Blush :o :o](/styles/default/custom/smilies/blush.gif)
ffice"
xmlns:x="urn:schemas-microsoft-com
![Blush :o :o](/styles/default/custom/smilies/blush.gif)
ffice:excel"
xmlns:ss="urn:schemas-microsoft-com
![Blush :o :o](/styles/default/custom/smilies/blush.gif)
ffice:spreadsheet">
- <customerInfo>
<uid>123</uid>
<lastname>smith</lastname>
<firstname>john</firstname>
</customerInfo>
- <customerInfo>
<uid>234</uid>
<lastname>jones</lastname>
<firstname>mary</firstname>
</customerInfo>
- <customerInfo>
<uid>345</uid>
<lastname>moore</lastname>
<firstname>pat</firstname>
</customerInfo>
</OneWellDefinedDS>