-
January 10th, 2012, 11:49 AM
#1
New to XSLT, so I apologize if I sound ignorant
We're starting to evaluate VS 2010, but right now I'm trying to do a simple Windows application in Visual Studio 2005 on an XP box.
Eventually, this will become a web service, but I want to test the XSLT file I am using in a simple application first.
Here is the XSLT file:
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match ="/table">
TEST <xsl:for-each select ="STYLE"></xsl:for-each>
</xsl:template>
</xsl:stylesheet>
The file is added to my project, XMLTest.
The code that generates and parses the file to change to a text file is as follows:
Module Module1
Sub Main()
Dim cn As New System.Data.SqlClient.SqlConnection
Dim cmd As New System.Data.SqlClient.SqlCommand
cn.ConnectionString = "database=ee8idbbd;server=jomar;uid=sa;pwd=brent"
cn.Open()
cmd.Connection = cn
cmd.CommandType = CommandType.StoredProcedure
cmd.CommandText = "bdg_proccaselabelstoprint"
cmd.Parameters.AddWithValue("@STYLE", "7207")
cmd.Parameters.AddWithValue("@COLORcode", "BK")
cmd.Parameters.AddWithValue("@SIZECODE", "S")
Dim da As New System.Data.SqlClient.SqlDataAdapter(cmd)
Dim ds As New Data.DataSet
da.Fill(ds)
ds.WriteXml("output.xml", XmlWriteMode.WriteSchema)
Dim document As New Xml.XmlDocument
Dim navigator As System.Xml.XPath.XPathNavigator
Dim transformer As New Xml.Xsl.XslCompiledTransform
Dim output As New System.IO.StringWriter
document.Load("output.xml")
navigator = document.CreateNavigator
transformer.Load("XSLTFile1.xslt")
transformer.Transform(navigator, Nothing, output)
Console.WriteLine(output.ToString)
Dim stream As New System.IO.FileStream("C:\output.txt", IO.FileMode.Create)
Dim writer As New System.IO.StreamWriter(stream)
writer.Write(output.ToString)
End Sub
End Module
A sample output XML file is as follows:
<?xml version="1.0" standalone="yes" ?>
- <NewDataSet>
- <xs:schema id="NewDataSet" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
- <xs:element name="NewDataSet" msdata:IsDataSet="true" msdata:UseCurrentLocale="true">
- <xs:complexType>
- <xs:choice minOccurs="0" maxOccurs="unbounded">
- <xs:element name="Table">
- <xs:complexType>
- <xs:sequence>
<xs:element name="Style" type="xs:string" minOccurs="0" />
<xs:element name="color" type="xs:string" minOccurs="0" />
<xs:element name="sizecode" type="xs:string" minOccurs="0" />
<xs:element name="GTIN" type="xs:string" minOccurs="0" />
<xs:element name="color_description" type="xs:string" minOccurs="0" />
<xs:element name="casenumber" type="xs:string" minOccurs="0" />
<xs:element name="PERMLOC" type="xs:string" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
- <Table>
<Style>7207</Style>
<color>BK</color>
<sizecode>S</sizecode>
<GTIN>08402350008095</GTIN>
<color_description>BLACK</color_description>
<casenumber>800000009</casenumber>
<PERMLOC>U16A6</PERMLOC>
</Table>
</NewDataSet>
When I run the VB code to input and transform the XML output I get a filenotfoundexception error that I can not figure out, because where it is expecting the XSLT file doesn't seem to make any sense.
If it were going to always be hosted on my machine, I'd use an absolute path, but it's not going to be, and I'm going to be switching to a Windows 7 x64 box after lunch anyway.
Can someone help me get through this?
-
January 10th, 2012, 12:27 PM
#2
Re: New to XSLT, so I apologize if I sound ignorant
Depends on where you created it. If you can find where it IS, and then, where it's LOOKING, it should become clearer
-
January 10th, 2012, 01:11 PM
#3
Re: New to XSLT, so I apologize if I sound ignorant
If I go Project->Add Component->XSLT file and give it a name, I would have thought it would be in the same directory as the source. Is that not correct?
It looks like it created the file in:
C:\Documents and Settings\bwhite\Local Settings\Application Data\Temporary Projects\XMLTest
But it is looking for the file in:
C:\Documents and Settings\bwhite\Local Settings\Application Data\Temporary Projects\XMLTest\bin\Debug\
Again, I don't want to hardcode the directory for the XSLT file because it will change when I move to a server (that doesn't actually have a C: drive)
-
January 10th, 2012, 09:23 PM
#4
Re: New to XSLT, so I apologize if I sound ignorant
Set the property COPYtoLOCAL to TRUE and it will copy it for you to either debug or release (to deploy)
-
January 12th, 2012, 03:04 PM
#5
Re: New to XSLT, so I apologize if I sound ignorant
Worked beautifully. Thank you
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|