Hi Sloan,
I followed your example and some information I found in internet and I
created a new version of my code and now I get the following:
This XML file does not appear to have any style information
associated with it. The document tree is shown below.
<urlset/>
This is really driving me crazy.
Do you or anyone else knows how to solve this?
----- New VB.NET code -----
' Create and load XSL document
Dim xslGoogle As XslCompiledTran sform = New XslCompiledTran sform
xslGoogle.Load( HttpContext.Cur rent.Server.Map Path(Configurat ionManager.AppS ettings("By27.A ssets")
& "/_Web/Google/SiteMap.xsl"))
' Create xpath document with XML document
Dim xpathGoogle As System.Xml.XPat h.XPathDocument = New
System.Xml.XPat h.XPathDocument (HttpContext.Cu rrent.Server.Ma pPath("~/Web.sitemap")
' Create memory stream
Dim msGoogle As System.IO.Strea m = New System.IO.Memor yStream
' Create XSL arguments list
Dim googleXslArgume nts As XsltArgumentLis t = New XsltArgumentLis t
googleXslArgume nts.AddParam("D omain", "",
"http://www.domain.com" )
' Transform XML document
xslGoogle.Trans form(xpathGoogl e, googleXslArgume nts, msGoogle)
' Flush the stream and set the position to 0
msGoogle.Flush( )
msGoogle.Positi on = 0
' Create stream reader
Dim srGoogle As System.IO.Strea mReader = New
System.IO.Strea mReader(msGoogl e)
' Display XML in browser
context.Respons e.Clear()
context.Respons e.ContentType = "text/xml; charset=utf-8"
context.Respons e.Write(srGoogl e.ReadToEnd)
context.Respons e.End()
---- XSL code ----
<?xml version="1.0" encoding="utf-8"?>
<xsl:styleshe et
version="1.0"
xmlns:xsl="http ://www.w3.org/1999/XSL/Transform"
xmlns="http://www.google.com/schemas/sitemap/0.84"
xmlns:dk="http://schemas.microso ft.com/AspNet/SiteMap-File-1.0">
<xsl:output method="xml" version="1.0" encoding="UTF-8"
indent="yes"/>
<xsl:param name="Domain"/>
<xsl:template match="dk:*"/>
<xsl:template match="@*|text( )|comment()"/>
<xsl:template match="/">
<xsl:element name="urlset">
<xsl:apply-templates select="//dk:siteMapNode[@google='true']"/>
</xsl:element>
</xsl:template>
<xsl:template match="dk:siteM apNode">
<xsl:element name="url">
<xsl:element name="loc">
<xsl:value-of select="$Domain " />
<xsl:value-of select="substri ng(@url, 3)"/>
</xsl:element>
<xsl:element name="lastmod">
<xsl:value-of select="@lastmo d"/>
</xsl:element>
<xsl:element name="changefre q">
<xsl:value-of select="@change freq"/>
</xsl:element>
<xsl:element name="priority" >
<xsl:value-of select="@priori ty"/>
</xsl:element>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
Thank You Very Much,
Miguel
sloan wrote:
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.S heet"?>
<Workbook xmlns="urn:sche mas-microsoft-com:office:spre adsheet"
xmlns:o="urn:sc hemas-microsoft-com:office:offi ce"
xmlns:x="urn:sc hemas-microsoft-com:office:exce l"
xmlns:ss="urn:s chemas-microsoft-com:office:spre adsheet"
xmlns:html="htt p://www.w3.org/TR/REC-html40">
<DocumentProper ties xmlns="urn:sche mas-microsoft-com:office:offi ce">
<Author>shollid ay</Author>
<LastAuthor>nam e</LastAuthor>
<Created>2003-12-22T18:58:08Z</Created>
<LastSaved>20 03-12-23T15:51:38Z</LastSaved>
<Company>organi zation</Company>
<Version>11.810 7</Version>
</DocumentPropert ies>
<ExcelWorkboo k xmlns="urn:sche mas-microsoft-com:office:exce l">
<WindowHeight>8 835</WindowHeight>
<WindowWidth>11 340</WindowWidth>
<WindowTopX>480 </WindowTopX>
<WindowTopY>120 </WindowTopY>
<ProtectStructu re>False</ProtectStructur e>
<ProtectWindows >False</ProtectWindows>
</ExcelWorkbook>
<Styles>
<Style ss:ID="Default" ss:Name="Normal ">
<Alignment ss:Vertical="Bo ttom"/>
<Borders/>
<Font/>
<Interior/>
<NumberFormat/>
<Protection/>
</Style>
</Styles>
<Worksheet ss:Name="Sheet1 ">
<Table ss:ExpandedColu mnCount="8" ss:ExpandedRowC ount="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 ">mylastnam e</Data></Cell>
<Cell><Data ss:Type="String ">myfirstna me</Data></Cell>
<Cell><Data ss:Type="String ">myaddress 1</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 ">statesvil le</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>
<WorksheetOptio ns xmlns="urn:sche mas-microsoft-com:office:exce l">
<Selected/>
<Panes>
<Pane>
<Number>3</Number>
<ActiveCol>1</ActiveCol>
</Pane>
</Panes>
<ProtectObjects >False</ProtectObjects>
<ProtectScenari os>False</ProtectScenario s>
</WorksheetOption s>
</Worksheet>
<Worksheet ss:Name="Sheet2 ">
<WorksheetOptio ns xmlns="urn:sche mas-microsoft-com:office:exce l">
<ProtectObjects >False</ProtectObjects>
<ProtectScenari os>False</ProtectScenario s>
</WorksheetOption s>
</Worksheet>
<Worksheet ss:Name="Sheet3 ">
<WorksheetOptio ns xmlns="urn:sche mas-microsoft-com:office:exce l">
<ProtectObjects >False</ProtectObjects>
<ProtectScenari os>False</ProtectScenario s>
</WorksheetOption s>
</Worksheet>
</Workbook>
---------------END----"START OUT" XML--------------------------------
-------- START XSL TO APPLY--------------------------
<xsl:styleshe et version="1.0"
xmlns:xsl="http ://www.w3.org/1999/XSL/Transform"
xmlns:o="urn:sc hemas-microsoft-com:office:offi ce"
xmlns:x="urn:sc hemas-microsoft-com:office:exce l"
xmlns:ss="urn:s chemas-microsoft-com:office:spre adsheet" >
<xsl:template match="/">
<OneWellDefined DS>
<!--<myRootPosition ><xsl:value-of select="positio n()"/></myRootPosition>-->
<xsl:apply-templates select="ss:Work book"/>
</OneWellDefinedD S>
</xsl:template>
<xsl:template match="ss:Workb ook">
<!--<myWorkbookPosi tion><xsl:value-of
select="positio n()"/></myWorkbookPosit ion>-->
<xsl:apply-templates select="ss:Work sheet"/>
</xsl:template>
<xsl:template match="ss:Works heet">
<!--<myWorksheetPos ition><xsl:valu e-of
select="positio n()"/></myWorksheetPosi tion>-->
<xsl:choose>
<xsl:when test="position( )=1">
<xsl:apply-templates select="ss:Tabl e"/>
</xsl:when>
<xsl:otherwis e>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="ss:Table ">
<!--<myTablePositio n><xsl:value-of
select="positio n()"/></myTablePosition >-->
<xsl:apply-templates select="ss:Row"/>
</xsl:template>
<xsl:template match="ss:Row">
<!--<myRowPosition> <xsl:value-of select="positio n()"/></myRowPosition>-->
<xsl:choose>
<xsl:when test="position( )=1">
</xsl:when>
<xsl:otherwis e>
<customerInfo >
<!--<myPosition><xs l:value-of select="positio n()"/></myPosition>-->
<xsl:apply-templates select="ss:Cell "/>
</customerInfo>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="ss:Cell" >
<!--<myCellPosition ><xsl:value-of
select="$varCur rentAttributePo sition"/></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="xfirstnam e" />
</xsl:when>
<xsl:otherwis e>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="xuid">
<uid><xsl:val ue-of select="."/></uid>
</xsl:template>
<xsl:template name="xlastname ">
<lastname><xsl: value-of select="."/></lastname>
</xsl:template>
<xsl:template name="xfirstnam e">
<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(s tring xmlFile, string xslFile, string outputFile)
{
try
{
//Create a new XslTransform object.
XslTransform xslt = new XslTransform();
//Load the stylesheet.
xslt.Load(xslFi le);
//Create a new XPathDocument and load the XML data to be transformed.
XPathDocument mydata = new XPathDocument(x mlFile);
//Create an XmlTextWriter which outputs to the console.
//XmlWriter writer = new XmlTextWriter(C onsole.Out);
//Transform the data and send the output to the console.
//xslt.Transform( mydata,null,wri ter, null);
xslt.Transform (xmlFile, outputFile);
}
catch (Exception ex)
{
debugMsg = ex.Message;
Console.WriteLi ne (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" ?>
- <OneWellDefined DS xmlns:o="urn:sc hemas-microsoft-com:office:offi ce"
xmlns:x="urn:sc hemas-microsoft-com:office:exce l"
xmlns:ss="urn:s chemas-microsoft-com:office:spre adsheet">
- <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>pa t</firstname>
</customerInfo>
</OneWellDefinedD S>