Wayne29
asked on
XSLT.TransForm method in C# :
Hi All,
My application takes in "Word 2003 XML" file name as an INPUT parameter and tries to APPLY XSLT file on this word 2003 document(xml) file and to extract the DATA ONLY entered by the user and puts into a file called as "out.xml".
The below is the code snippet.
The last statement in the code snippet is not working fine.
Can any body correct this and let me know.
'Transform the Document / XML file into PURE XML DATA ONLY FILE
''Create a new XslTransform object.
Dim xslt As New XslTransform
''''Load the stylesheet.
xslt.Load(CType("c:\inetpu b\wwwroot\ Assessment \xsl\dataO nly.xslt", String))
''''Create a new XPathDocument and load the XML data to be transformed.
Dim mydata As New XPathDocument("sample.xml" )
Dim resolver As XmlUrlResolver = New XmlUrlResolver
resolver.Credentials = System.Net.CredentialCache .DefaultCr edentials
''''Transform the data and send the output to the console.
xslt.Transform(SaveLocatio n, "c:\inetpub\wwwroot\Assess ment\Templ ates\out.x ml", resolver)
My application takes in "Word 2003 XML" file name as an INPUT parameter and tries to APPLY XSLT file on this word 2003 document(xml) file and to extract the DATA ONLY entered by the user and puts into a file called as "out.xml".
The below is the code snippet.
The last statement in the code snippet is not working fine.
Can any body correct this and let me know.
'Transform the Document / XML file into PURE XML DATA ONLY FILE
''Create a new XslTransform object.
Dim xslt As New XslTransform
''''Load the stylesheet.
xslt.Load(CType("c:\inetpu
''''Create a new XPathDocument and load the XML data to be transformed.
Dim mydata As New XPathDocument("sample.xml"
Dim resolver As XmlUrlResolver = New XmlUrlResolver
resolver.Credentials = System.Net.CredentialCache
''''Transform the data and send the output to the console.
xslt.Transform(SaveLocatio
Can you expand a little on "Not working fine" ?
ASKER
Thanks Carl for your timely reponse.
"Not working fine", in the sense, the "out.xml" is coming EMPTY only with the ROOT TAG.
So for the timebeing I have used the below code to get "out.xml" only with the data.
But I do not want the below code to be in place as it is an additional overhead of loading Word Instance.
I would be very happy if my earlier approach (above) works!
So Basically what I am doing is, "Saving the file (doc/xml) which the user has given to me, by Applying XSLT"
to get PURE XML (data only). With this pure xml file, I am putting the values back to database. So next time he generates my template, he sees the latest values .....
Dim wordApp As Word.ApplicationClass
Dim wordDoc As Word.DocumentClass
Try
wordApp = New Word.ApplicationClass
wordDoc = New Word.DocumentClass
wordApp.Visible = True
wordDoc = wordApp.Documents.Open(tem pfilename)
' x.Documents.Open(FileName: =tempfilen ame, ConfirmConversions:=False _
', ReadOnly:=False, AddToRecentFiles:=False, PasswordDocument:="", _
'PasswordTemplate:="", Revert:=False, WritePasswordDocument:="", _
'WritePasswordTemplate:="" , Format:=Word.WdOpenFormat. wdOpenForm atAuto, XMLTransform:="")
wordDoc.Activate()
With wordApp.ActiveDocument
.XMLSaveDataOnly = False
.XMLUseXSLTWhenSaving = True
.XMLSaveThroughXSLT = _
"C:\inetpub\wwwroot\Assess ment\xsl\d ataOnly.xs lt"
.XMLHideNamespaces = False
.XMLShowAdvancedErrors = True
.XMLSchemaReferences.HideV alidationE rrors = False
.XMLSchemaReferences.Autom aticValida tion = True
.XMLSchemaReferences.Ignor eMixedCont ent = False
.XMLSchemaReferences.Allow SaveAsXMLW ithoutVali dation = True
.XMLSchemaReferences.ShowP laceholder Text = False
End With
wordApp.ActiveDocument.Sav eAs(filena me:="c:\in etpub\wwwr oot\Assess ment\Templ ates\out.x ml", FileFormat:=Word.WdSaveFor mat.wdForm atXML, _
LockComments:=False, Password:="", AddToRecentFiles:=True, _
WritePassword:="", ReadOnlyRecommended:=False , EmbedTrueTypeFonts:=False, _
SaveNativePictureFormat:=F alse, SaveFormsData:=False, SaveAsAOCELetter:= _
False)
wordDoc.Close()
wordApp.Quit()
wordApp = Nothing
wordDoc = Nothing
Catch ex As Exception
Throw New Exception(ex.Message.ToStr ing())
Finally
wordApp = Nothing
wordDoc = Nothing
End Try
"Not working fine", in the sense, the "out.xml" is coming EMPTY only with the ROOT TAG.
So for the timebeing I have used the below code to get "out.xml" only with the data.
But I do not want the below code to be in place as it is an additional overhead of loading Word Instance.
I would be very happy if my earlier approach (above) works!
So Basically what I am doing is, "Saving the file (doc/xml) which the user has given to me, by Applying XSLT"
to get PURE XML (data only). With this pure xml file, I am putting the values back to database. So next time he generates my template, he sees the latest values .....
Dim wordApp As Word.ApplicationClass
Dim wordDoc As Word.DocumentClass
Try
wordApp = New Word.ApplicationClass
wordDoc = New Word.DocumentClass
wordApp.Visible = True
wordDoc = wordApp.Documents.Open(tem
' x.Documents.Open(FileName:
', ReadOnly:=False, AddToRecentFiles:=False, PasswordDocument:="", _
'PasswordTemplate:="", Revert:=False, WritePasswordDocument:="",
'WritePasswordTemplate:=""
wordDoc.Activate()
With wordApp.ActiveDocument
.XMLSaveDataOnly = False
.XMLUseXSLTWhenSaving = True
.XMLSaveThroughXSLT = _
"C:\inetpub\wwwroot\Assess
.XMLHideNamespaces = False
.XMLShowAdvancedErrors = True
.XMLSchemaReferences.HideV
.XMLSchemaReferences.Autom
.XMLSchemaReferences.Ignor
.XMLSchemaReferences.Allow
.XMLSchemaReferences.ShowP
End With
wordApp.ActiveDocument.Sav
LockComments:=False, Password:="", AddToRecentFiles:=True, _
WritePassword:="", ReadOnlyRecommended:=False
SaveNativePictureFormat:=F
False)
wordDoc.Close()
wordApp.Quit()
wordApp = Nothing
wordDoc = Nothing
Catch ex As Exception
Throw New Exception(ex.Message.ToStr
Finally
wordApp = Nothing
wordDoc = Nothing
End Try
Can you post the starting section of the XML ? Its possibly a namespace issue in your document.
ASKER
The below is the starting section of the XML file (word 2003 document saved as XML file)
<?xml version="1.0" encoding="UTF-8" standalone="yes"?><?mso-ap plication progid="Word.Document"?>
<w:wordDocument xmlns:w="http://schemas.microsoft.com/office/word/2003/wordml" xmlns:v="urn:schemas-micro soft-com:v ml" xmlns:w10="urn:schemas-mic rosoft-com :office:wo rd" xmlns:sl="http://schemas.microsoft.com/schemaLibrary/2003/core" xmlns:aml="http://schemas.microsoft.com/aml/2001/core" xmlns:wx="http://schemas.microsoft.com/office/word/2003/auxHint" xmlns:o="urn:schemas-micro soft-com:o ffice:offi ce" xmlns:dt="uuid:C2F41010-65 B3-11d1-A2 9F-00AA00C 14882" xmlns:ns0="http://Greenpark.com/Namespace1" w:macrosPresent="no" w:embeddedObjPresent="no" w:ocxPresent="no" xml:space="preserve">
<?xml version="1.0" encoding="UTF-8" standalone="yes"?><?mso-ap
<w:wordDocument xmlns:w="http://schemas.microsoft.com/office/word/2003/wordml" xmlns:v="urn:schemas-micro
And have you catered for all the required namespaces in your XSL ?
ASKER
I think you are about to catch it.
Please find below the complete XSLT file which extracts "DATA ONLY" for a given XML/DOC of Word 2003.
But I am not sure which namespace to be changed to meet my requirements.
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0"
exclude-result-prefixes="w v w10 sl aml wx xsl o dt st1"
xmlns:w="http://schemas.microsoft.com/office/word/2003/wordml"
xmlns:v="urn:schemas-micro soft-com:v ml"
xmlns:w10="urn:schemas-mic rosoft-com :office:wo rd"
xmlns:sl="http://schemas.microsoft.com/schemaLibrary/2003/core"
xmlns:aml="http://schemas.microsoft.com/aml/2001/core"
xmlns:wx="http://schemas.microsoft.com/office/word/2003/auxHint"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:o="urn:schemas-micro soft-com:o ffice:offi ce"
xmlns:dt="uuid:C2F41010-65 B3-11d1-A2 9F-00AA00C 14882"
xmlns:st1="urn:schemas-mic rosoft-com :office:sm arttags">
<xsl:output encoding="utf-8"/>
<!-- root template -->
<xsl:template match="/">
<Assessment>
<xsl:apply-templates select="w:wordDocument/w:b ody"/>
</Assessment>
</xsl:template>
<!-- outside of root XML element -->
<xsl:template match="w:* | v:* | w10:* | sl:* | aml:* | wx:* | o:* | dt:* | st1:* | *[@w:st='on']">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="*">
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:apply-templates mode="arbitraryXML"/>
</xsl:copy>
</xsl:template>
<xsl:template match="text()"/>
<!-- inside root XML element -->
<xsl:template match="w:* | v:* | w10:* | sl:* | aml:* | wx:* | o:* | dt:* | st1:* | *[@w:st='on']" mode="arbitraryXML">
<xsl:apply-templates mode="arbitraryXML"/>
</xsl:template>
<xsl:template match="*" mode="arbitraryXML">
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:apply-templates mode="arbitraryXML"/>
</xsl:copy>
</xsl:template>
<xsl:template match="text()" mode="arbitraryXML"/>
<xsl:template match="w:t" mode="arbitraryXML">
<xsl:value-of select="."/>
</xsl:template>
</xsl:stylesheet>
Please find below the complete XSLT file which extracts "DATA ONLY" for a given XML/DOC of Word 2003.
But I am not sure which namespace to be changed to meet my requirements.
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0"
exclude-result-prefixes="w
xmlns:w="http://schemas.microsoft.com/office/word/2003/wordml"
xmlns:v="urn:schemas-micro
xmlns:w10="urn:schemas-mic
xmlns:sl="http://schemas.microsoft.com/schemaLibrary/2003/core"
xmlns:aml="http://schemas.microsoft.com/aml/2001/core"
xmlns:wx="http://schemas.microsoft.com/office/word/2003/auxHint"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:o="urn:schemas-micro
xmlns:dt="uuid:C2F41010-65
xmlns:st1="urn:schemas-mic
<xsl:output encoding="utf-8"/>
<!-- root template -->
<xsl:template match="/">
<Assessment>
<xsl:apply-templates select="w:wordDocument/w:b
</Assessment>
</xsl:template>
<!-- outside of root XML element -->
<xsl:template match="w:* | v:* | w10:* | sl:* | aml:* | wx:* | o:* | dt:* | st1:* | *[@w:st='on']">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="*">
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:apply-templates mode="arbitraryXML"/>
</xsl:copy>
</xsl:template>
<xsl:template match="text()"/>
<!-- inside root XML element -->
<xsl:template match="w:* | v:* | w10:* | sl:* | aml:* | wx:* | o:* | dt:* | st1:* | *[@w:st='on']" mode="arbitraryXML">
<xsl:apply-templates mode="arbitraryXML"/>
</xsl:template>
<xsl:template match="*" mode="arbitraryXML">
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:apply-templates mode="arbitraryXML"/>
</xsl:copy>
</xsl:template>
<xsl:template match="text()" mode="arbitraryXML"/>
<xsl:template match="w:t" mode="arbitraryXML">
<xsl:value-of select="."/>
</xsl:template>
</xsl:stylesheet>
Do you have a more complete XML doc I could test against ?
ASKER
Please find below the complete Word ML file of my document.
Thanks for your efforts.
<?xml version="1.0" encoding="UTF-8" standalone="yes"?><?mso-ap plication progid="Word.Document"?><w :wordDocum ent xmlns:w="http://schemas.microsoft.com/office/word/2003/wordml" xmlns:v="urn:schemas-micro soft-com:v ml" xmlns:w10="urn:schemas-mic rosoft-com :office:wo rd" xmlns:sl="http://schemas.microsoft.com/schemaLibrary/2003/core" xmlns:aml="http://schemas.microsoft.com/aml/2001/core" xmlns:wx="http://schemas.microsoft.com/office/word/2003/auxHint" xmlns:o="urn:schemas-micro soft-com:o ffice:offi ce" xmlns:dt="uuid:C2F41010-65 B3-11d1-A2 9F-00AA00C 14882" xmlns:ns0="http://Greenpark.com/Namespace1" w:macrosPresent="no" w:embeddedObjPresent="no" w:ocxPresent="no" xml:space="preserve"><o:Do cumentProp erties><o: Title>Test Form</o:Title><o:Author>Wa yne</o:Aut hor><o:Las tAuthor>Wa yne F</o:LastAuthor><o:Revisio n>29</o:Re vision><o: TotalTime> 16</o:Tota lTime><o:C reated>200 6-04-04T09 :38:00Z</o :Created>< o:LastSave d>2006-04- 07T04:55:0 0Z</o:Last Saved><o:P ages>1</o: Pages><o:W ords>70</o :Words><o: Characters >404</o:Ch aracters>< o:Company> RedFort Limited</o:Company><o:Line s>3</o:Lin es><o:Para graphs>1</ o:Paragrap hs><o:Char actersWith Spaces>473 </o:Charac tersWithSp aces><o:Ve rsion>11.5 604</o:Ver sion></o:D ocumentPro perties><w :fonts><w: defaultFon ts w:ascii="Times New Roman" w:fareast="Times New Roman" w:h-ansi="Times New Roman" w:cs="Times New Roman" /></w:fonts><w:styles><w:v ersionOfBu iltInStyle names w:val="4" /><w:latentStyles w:defLockedState="off" w:latentStyleCount="156" /><w:style w:type="paragraph" w:default="on" w:styleId="Normal"><w:name w:val="Normal" /><w:rsid w:val="00DA6A64" /><w:rPr><wx:font wx:val="Times New Roman" /><w:sz w:val="24" /><w:sz-cs w:val="24" /><w:lang w:val="EN-GB" w:fareast="EN-US" w:bidi="AR-SA" /></w:rPr></w:style><w:sty le w:type="character" w:default="on" w:styleId="DefaultParagrap hFont"><w: name w:val="Default Paragraph Font" /><w:semiHidden /></w:style><w:style w:type="table" w:default="on" w:styleId="TableNormal"><w :name w:val="Normal Table" /><wx:uiName wx:val="Table Normal" /><w:semiHidden /><w:rPr><wx:font wx:val="Times New Roman" /></w:rPr><w:tblPr><w:tblI nd w:w="0" w:type="dxa" /><w:tblCellMar><w:top w:w="0" w:type="dxa" /><w:left w:w="108" w:type="dxa" /><w:bottom w:w="0" w:type="dxa" /><w:right w:w="108" w:type="dxa" /></w:tblCellMar></w:tblPr ></w:style ><w:style w:type="list" w:default="on" w:styleId="NoList"><w:name w:val="No List" /><w:semiHidden /></w:style><w:style w:type="table" w:styleId="TableGrid"><w:n ame w:val="Table Grid" /><w:basedOn w:val="TableNormal" /><w:rsid w:val="00DA6A64" /><w:rPr><wx:font wx:val="Times New Roman" /></w:rPr><w:tblPr><w:tblI nd w:w="0" w:type="dxa" /><w:tblBorders><w:top w:val="single" w:sz="4" wx:bdrwidth="10" w:space="0" w:color="auto" /><w:left w:val="single" w:sz="4" wx:bdrwidth="10" w:space="0" w:color="auto" /><w:bottom w:val="single" w:sz="4" wx:bdrwidth="10" w:space="0" w:color="auto" /><w:right w:val="single" w:sz="4" wx:bdrwidth="10" w:space="0" w:color="auto" /><w:insideH w:val="single" w:sz="4" wx:bdrwidth="10" w:space="0" w:color="auto" /><w:insideV w:val="single" w:sz="4" wx:bdrwidth="10" w:space="0" w:color="auto" /></w:tblBorders><w:tblCel lMar><w:to p w:w="0" w:type="dxa" /><w:left w:w="108" w:type="dxa" /><w:bottom w:w="0" w:type="dxa" /><w:right w:w="108" w:type="dxa" /></w:tblCellMar></w:tblPr ></w:style ></w:style s><w:docPr ><w:view w:val="print" /><w:zoom w:percent="100" /><w:doNotEmbedSystemFonts /><w:proofState w:spelling="clean" w:grammar="clean" /><w:attachedTemplate w:val="" /><w:documentProtection w:edit="forms" w:formatting="on" w:enforcement="off" /><w:defaultTabStop w:val="720" /><w:drawingGridHorizontal Spacing w:val="187" /><w:displayVerticalDrawin gGridEvery w:val="2" /><w:punctuationKerning /><w:characterSpacingContr ol w:val="DontCompress" /><w:optimizeForBrowser /><w:validateAgainstSchema /><w:saveInvalidXML w:val="off" /><w:ignoreMixedContent w:val="off" /><w:alwaysShowPlaceholder Text w:val="off" /><w:compat><w:breakWrappe dTables /><w:snapToGridInCell /><w:wrapTextWithPunct /><w:useAsianBreakRules /><w:dontGrowAutofit /></w:compat></w:docPr><w: body><wx:s ect><w:p /><w:p /><w:p /><w:p /><w:p><w:pPr><w:rPr><w:b /><w:u w:val="single" /></w:rPr></w:pPr><w:r><w: rPr><w:b /><w:u w:val="single" /></w:rPr><w:t>Test Form</w:t></w:r></w:p><w:p /><w:p><w:r><w:t>Title:</w :t></w:r>< w:r><w:tab wx:wTab="285" wx:tlc="none" wx:cTlc="4" /></w:r><w:r><w:tab wx:wTab="720" wx:tlc="none" wx:cTlc="11" /></w:r><w:r><w:tab wx:wTab="720" wx:tlc="none" wx:cTlc="11" /></w:r><aml:annotation aml:id="0" w:type="Word.Bookmark.Star t" w:name="Title" /><w:r><w:fldChar w:fldCharType="begin"><w:f ldData>/// //2aAAAAAA AUAVABpAHQ AbABlAAAAA AAAAAAAAAA AAAAAAAAAA AAAAAAAAP/ /AwAAAAIAT QBy
AAMATQByAHMABABNAGkAcwBzAA ==
</w:fldData></w:fldChar></ w:r><w:r>< w:instrTex t> FORMDROPDOWN </w:instrText></w:r><w:r>< w:fldChar w:fldCharType="end" /></w:r><aml:annotation aml:id="0" w:type="Word.Bookmark.End" /><Title><w:r><w:t>Mrs.</w :t></w:r>< /Title></w :p><w:p /><w:p><w:r><w:t>Forename: </w:t></w: r><w:r><w: tab wx:wTab="480" wx:tlc="none" wx:cTlc="7" /></w:r><w:r><w:tab wx:wTab="720" wx:tlc="none" wx:cTlc="11" /></w:r><aml:annotation aml:id="1" w:type="Word.Bookmark.Star t" w:name="Text1" /><Forename><w:r><w:t /></w:r><w:r><w:fldChar w:fldCharType="begin"><w:f ldData>/// //wAAMgAAA AAAAAAAAAA AAAAAAAAAA AAAAAAAAAA AAAAAAAA=
</w:fldData></w:fldChar></ w:r><w:r>< w:instrTex t> FORMTEXT </w:instrText></w:r><w:r>< w:fldChar w:fldCharType="separate" /></w:r><w:r><w:rPr><w:noP roof /></w:rPr><w:t>Mike</w:t>< /w:r><w:r> <w:fldChar w:fldCharType="end" /></w:r></Forename></w:p>< w:p /><w:p><w:r><w:t>Surname:< /w:t></w:r ><w:r><w:t ab wx:wTab="600" wx:tlc="none" wx:cTlc="9" /></w:r><w:r><w:tab wx:wTab="720" wx:tlc="none" wx:cTlc="11" /></w:r><aml:annotation aml:id="2" w:type="Word.Bookmark.Star t" w:name="Text2" /><Surname><w:r><w:t /></w:r><w:r><w:fldChar w:fldCharType="begin"><w:f ldData>/// //wAAMgAAA AAAAAAAAAA AAAAAAAAAA AAAAAAAAAA AAAAAAAA=
</w:fldData></w:fldChar></ w:r><w:r>< w:instrTex t> FORMTEXT </w:instrText></w:r><w:r>< w:fldChar w:fldCharType="separate" /></w:r><w:r><w:rPr><w:noP roof /></w:rPr><w:t>Gatting Sir Mike Gatting</w:t></w:r><w:r><w :fldChar w:fldCharType="end" /></w:r></Surname></w:p><w :p /><w:p /><w:p><w:pPr><w:rPr><w:b /><w:u w:val="single" /></w:rPr></w:pPr><w:r><w: rPr><w:b /><w:u w:val="single" /></w:rPr><w:t>Address</w: t></w:r></ w:p><w:p>< w:r><w:tab wx:wTab="720" wx:tlc="none" wx:cTlc="11" /><w:t>Line 1:</w:t></w:r><w:r><w:tab wx:wTab="105" wx:tlc="none" wx:cTlc="1" /></w:r><w:r><w:tab wx:wTab="720" wx:tlc="none" wx:cTlc="11" /></w:r><Address1><w:r><w: t /></w:r><w:r><w:fldChar w:fldCharType="begin"><w:f ldData>/// //wAAAAAAA AUAVABlAHg AdAA4AAAAA AAAAAAAAAA AAAAAAAAAA AAAAAAAAAA A
</w:fldData></w:fldChar></ w:r><w:r>< w:instrTex t> FORMTEXT </w:instrText></w:r><w:r>< w:fldChar w:fldCharType="separate" /></w:r><w:r><w:rPr><w:noP roof /></w:rPr><w:t>54 Green Park</w:t></w:r><w:r><w:fl dChar w:fldCharType="end" /></w:r><aml:annotation aml:id="3" w:type="Word.Bookmark.End" /></Address1></w:p><w:p><w :r><w:tab wx:wTab="720" wx:tlc="none" wx:cTlc="11" /><w:t>Line 2:</w:t></w:r><w:r><w:tab wx:wTab="105" wx:tlc="none" wx:cTlc="1" /></w:r><w:r><w:tab wx:wTab="720" wx:tlc="none" wx:cTlc="11" /></w:r><Address2><w:r><w: t /></w:r><w:r><w:fldChar w:fldCharType="begin"><w:f ldData>/// //wAAAAAAA AUAVABlAHg AdAA5AAAAA AAAAAAAAAA AAAAAAAAAA AAAAAAAAAA A
</w:fldData></w:fldChar></ w:r><w:r>< w:instrTex t> FORMTEXT </w:instrText></w:r><w:r>< w:fldChar w:fldCharType="separate" /></w:r><w:r><w:rPr><w:noP roof /></w:rPr><w:t>Balmoral Avenue</w:t></w:r><w:r><w: fldChar w:fldCharType="end" /></w:r><aml:annotation aml:id="4" w:type="Word.Bookmark.End" /></Address2></w:p><w:p><w :r><w:tab wx:wTab="720" wx:tlc="none" wx:cTlc="11" /><w:t>Line 3:</w:t></w:r><w:r><w:tab wx:wTab="105" wx:tlc="none" wx:cTlc="1" /></w:r><w:r><w:tab wx:wTab="720" wx:tlc="none" wx:cTlc="11" /></w:r><Address3><w:r><w: t /></w:r><w:r><w:fldChar w:fldCharType="begin"><w:f ldData>/// //wAAAAAAA AYAVABlAHg AdAAxADAAA AAAAAAAAAA AAAAAAAAAA AAAAAAAAAA AAAA=
</w:fldData></w:fldChar></ w:r><w:r>< w:instrTex t> FORMTEXT </w:instrText></w:r><w:r>< w:fldChar w:fldCharType="separate" /></w:r><w:r><w:rPr><w:noP roof /></w:rPr><w:t>Derry</w:t> </w:r><w:r ><w:fldCha r w:fldCharType="end" /></w:r><aml:annotation aml:id="5" w:type="Word.Bookmark.End" /></Address3></w:p><w:p><w :r><w:tab wx:wTab="720" wx:tlc="none" wx:cTlc="11" /><w:t>Line 4:</w:t></w:r><w:r><w:tab wx:wTab="105" wx:tlc="none" wx:cTlc="1" /></w:r><w:r><w:tab wx:wTab="720" wx:tlc="none" wx:cTlc="11" /></w:r><Address4><w:r><w: t /></w:r><w:r><w:fldChar w:fldCharType="begin"><w:f ldData>/// //wAAAAAAA AYAVABlAHg AdAAxADEAA AAAAAAAAAA AAAAAAAAAA AAAAAAAAAA AAAA=
</w:fldData></w:fldChar></ w:r><w:r>< w:instrTex t> FORMTEXT </w:instrText></w:r><w:r>< w:fldChar w:fldCharType="separate" /></w:r><w:r><w:rPr><w:noP roof /></w:rPr><w:t>Derry</w:t> </w:r><w:r ><w:fldCha r w:fldCharType="end" /></w:r><aml:annotation aml:id="6" w:type="Word.Bookmark.End" /></Address4></w:p><w:p><w :r><w:tab wx:wTab="720" wx:tlc="none" wx:cTlc="11" /><w:t>Postcode:</w:t></w: r><w:r><w: tab wx:wTab="540" wx:tlc="none" wx:cTlc="8" /></w:r><aml:annotation aml:id="7" w:type="Word.Bookmark.Star t" w:name="Text7" /><Postcode><w:r><w:t /></w:r><w:r><w:fldChar w:fldCharType="begin"><w:f ldData>/// //wAACAAAA AAAAAAAAAA AAAAAAAAAA AAAAAAAAAA AAAAAAAA=
</w:fldData></w:fldChar></ w:r><w:r>< w:instrTex t> FORMTEXT </w:instrText></w:r><w:r>< w:fldChar w:fldCharType="separate" /></w:r><w:r><w:rPr><w:noP roof /></w:rPr><w:t>DT2 3GH</w:t></w:r><w:r><w:fld Char w:fldCharType="end" /></w:r></Postcode></w:p>< w:p /><w:p /><w:p><w:r><w:t>Marital Status:</w:t></w:r><w:r><w :tab wx:wTab="135" wx:tlc="none" wx:cTlc="1" /></w:r><w:r><w:tab wx:wTab="720" wx:tlc="none" wx:cTlc="11" /></w:r><aml:annotation aml:id="8" w:type="Word.Bookmark.Star t" w:name="MaritalStatus" /><w:r><w:fldChar w:fldCharType="begin"><w:f ldData>/// //2bAAAAAA A0ATQBhAHI AaQB0AGEAb ABTAHQAYQB 0AHUAcwAAA AAAAAAAAAA AAAAAAAAAA AAA
AAAAAAD//wMAAAAHAE0AYQByAH IAaQBlAGQA BgBTAGkAbg BnAGwAZQAI AEQAaQB2AG 8AcgBjAGUA
ZAA=
</w:fldData></w:fldChar></ w:r><w:r>< w:instrTex t> FORMDROPDOWN </w:instrText></w:r><w:r>< w:fldChar w:fldCharType="end" /></w:r><aml:annotation aml:id="8" w:type="Word.Bookmark.End" /><MaritalStatus><w:r><w:t >Divorced< /w:t></w:r ></Marital Status><w: r><w:t> </w:t></w:r></w:p><w:p /><w:p><w:r><w:t>Date of Birth</w:t></w:r><w:proofE rr w:type="gramStart" /><w:r><w:t>:</w:t></w:r>< w:r><w:tab wx:wTab="225" wx:tlc="none" wx:cTlc="3" /></w:r><w:r><w:tab wx:wTab="720" wx:tlc="none" wx:cTlc="11" /></w:r><aml:annotation aml:id="9" w:type="Word.Bookmark.Star t" w:name="Text4" /><DOB><w:r><w:t /></w:r><w:r><w:fldChar w:fldCharType="begin"><w:f ldData>/// //wAQCgAAA AAAAAAAAAA ACgBkAGQAL wBNAE0ALwB 5AHkAeQB5A AAAAAAAAAA AAAAAAAAAA AAA
AA==
</w:fldData></w:fldChar></ w:r><w:r>< w:instrTex t> FORMTEXT </w:instrText></w:r><w:r>< w:fldChar w:fldCharType="separate" /></w:r><w:r><w:rPr><w:noP roof /></w:rPr><w:t>25/12/1965< /w:t></w:r ><w:proofE rr w:type="gramEnd" /><w:r><w:fldChar w:fldCharType="end" /></w:r></DOB><w:r><w:t> </w:t></w:r><w:proofErr w:type="spellStart" /><w:proofErr w:type="gramStart" /><w:r><w:t>dd/mm/yyyy</w: t></w:r><w :proofErr w:type="spellEnd" /><w:proofErr w:type="gramEnd" /></w:p><w:p /><w:p><w:r><w:t>Height</w :t></w:r>< w:proofErr w:type="gramStart" /><w:r><w:t>:</w:t></w:r>< w:r><w:tab wx:wTab="90" wx:tlc="none" wx:cTlc="1" /></w:r><w:r><w:tab wx:wTab="720" wx:tlc="none" wx:cTlc="11" /></w:r><w:r><w:tab wx:wTab="720" wx:tlc="none" wx:cTlc="11" /></w:r><aml:annotation aml:id="10" w:type="Word.Bookmark.Star t" w:name="Text5" /><Height><w:r><w:t /></w:r><w:r><w:fldChar w:fldCharType="begin"><w:f ldData>/// //wAICgAAA AAAAAAAAAA ABAAwAC4AM AAwAAAAAAA AAAAAAAAAA AAAAAAAAA= =
</w:fldData></w:fldChar></ w:r><w:r>< w:instrTex t> FORMTEXT </w:instrText></w:r><w:r>< w:fldChar w:fldCharType="separate" /></w:r><w:r><w:rPr><w:noP roof /></w:rPr><w:t>1.65 M</w:t></w:r><w:proofErr w:type="gramEnd" /><w:r><w:fldChar w:fldCharType="end" /></w:r></Height><w:r><w:t > </w:t></w:r><w:proofErr w:type="gramStart" /><w:r><w:t>m</w:t></w:r>< w:proofErr w:type="gramEnd" /></w:p><w:p /><w:p><w:r><w:t>Weight</w :t></w:r>< w:proofErr w:type="gramStart" /><w:r><w:t>:</w:t></w:r>< w:r><w:tab wx:wTab="30" wx:tlc="none" wx:cTlc="0" /></w:r><w:r><w:tab wx:wTab="720" wx:tlc="none" wx:cTlc="11" /></w:r><aml:annotation aml:id="11" w:type="Word.Bookmark.Star t" w:name="Text6" /><Weight><w:r><w:t /></w:r><w:r><w:fldChar w:fldCharType="begin"><w:f ldData>/// //wAICgAAA AAAAAAAAAA ABAAwAC4AM AAwAAAAAAA AAAAAAAAAA AAAAAAAAA= =
</w:fldData></w:fldChar></ w:r><w:r>< w:instrTex t> FORMTEXT </w:instrText></w:r><w:r>< w:fldChar w:fldCharType="separate" /></w:r><w:r><w:rPr><w:noP roof /></w:rPr><w:t>75.00 kg</w:t></w:r><w:proofErr w:type="gramEnd" /><w:r><w:fldChar w:fldCharType="end" /></w:r></Weight><w:r><w:t > </w:t></w:r><w:proofErr w:type="gramStart" /><w:r><w:t>kg</w:t></w:r> <w:proofEr r w:type="gramEnd" /></w:p><w:p /><w:p /><w:p><w:r><w:t>Admit to RABIU:</w:t></w:r><w:r><w: tab wx:wTab="555" wx:tlc="none" wx:cTlc="8" /></w:r><aml:annotation aml:id="12" w:type="Word.Bookmark.Star t" w:name="AdmitToRABIU" /><w:r><w:fldChar w:fldCharType="begin"><w:f ldData>/// //2bAAAAAA AwAQQBkAG0 AaQB0AFQAb wBSAEEAQgB JAFUAAAAAA AAAAAAAAAA AAAAAAAAAA AAA
AAAA//8CAAAAAwBZAGUAcwACAE 4AbwA=
</w:fldData></w:fldChar></ w:r><w:r>< w:instrTex t> FORMDROPDOWN </w:instrText></w:r><w:r>< w:fldChar w:fldCharType="end" /></w:r><aml:annotation aml:id="12" w:type="Word.Bookmark.End" /><AdmitToRABIU><w:r><w:t> Yes</w:t>< /w:r></Adm itToRABIU> <w:r><w:t> </w:t></w:r></w:p><w:sectP r><w:pgSz w:w="11909" w:h="16834" w:code="9" /><w:pgMar w:top="1440" w:right="1800" w:bottom="1440" w:left="1800" w:header="720" w:footer="720" w:gutter="0" /><w:cols w:space="720" /><w:docGrid w:line-pitch="360" /></w:sectPr></wx:sect></w :body></w: wordDocume nt>
Thanks for your efforts.
<?xml version="1.0" encoding="UTF-8" standalone="yes"?><?mso-ap
AAMATQByAHMABABNAGkAcwBzAA
</w:fldData></w:fldChar></
</w:fldData></w:fldChar></
</w:fldData></w:fldChar></
</w:fldData></w:fldChar></
</w:fldData></w:fldChar></
</w:fldData></w:fldChar></
</w:fldData></w:fldChar></
</w:fldData></w:fldChar></
AAAAAAD//wMAAAAHAE0AYQByAH
ZAA=
</w:fldData></w:fldChar></
AA==
</w:fldData></w:fldChar></
</w:fldData></w:fldChar></
</w:fldData></w:fldChar></
AAAA//8CAAAAAwBZAGUAcwACAE
</w:fldData></w:fldChar></
It works ok for me.
The only thing I changed in your code was to replace "SaveLocation" with the path to the source XML file. I'm not sure what "SaveLocation" refers to in your code, so maybe this is the cause of the problem.
The only thing I changed in your code was to replace "SaveLocation" with the path to the source XML file. I'm not sure what "SaveLocation" refers to in your code, so maybe this is the cause of the problem.
ASKER
Please find the entire code snippet of calling the same.
User has uploaded a file and i have saved it into SERVER in a predefined folder whose path is in "SaveLocation" variable.
Private Sub btnUpload_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpload.Click
REM Upload File
REM Update Database
Dim blUpdate As Boolean
Dim SaveLocation As String
Dim objXSLT As New XslTransform
Dim dSet As New DataSet
Dim i, j As Integer
Try
If Not File1.PostedFile Is Nothing And File1.PostedFile.ContentLe ngth > 0 Then
Dim fn As String = System.IO.Path.GetFileName (File1.Pos tedFile.Fi leName)
SaveLocation = Server.MapPath("Templates" ) & "\" & fn.Replace("doc", "xml")
Try
File1.PostedFile.SaveAs(Sa veLocation )
Response.Write("The file has been uploaded.")
Catch Exc As Exception
Response.Write("Error: " & Exc.Message)
End Try
Else
Response.Write("Please select a file to upload.")
End If
'Transform the Document / XML file into PURE XML DATA ONLY FILE
''Create a new XslTransform object.
Dim xslt As New XslTransform
''''Load the stylesheet.
xslt.Load(CType("c:\inetpu b\wwwroot\ Assessment \xsl\dataO nly.xslt", String))
''''Create a new XPathDocument and load the XML data to be transformed.
Dim mydata As New XPathDocument(SaveLocation )
Dim resolver As XmlUrlResolver = New XmlUrlResolver
resolver.Credentials = System.Net.CredentialCache .DefaultCr edentials
''''Transform the data and send the output to the console.
xslt.Transform(SaveLocatio n, "c:\inetpub\wwwroot\Assess ment\Templ ates\out.x ml", resolver)
'Read this XML and put data into dataset
'SaveAsDataOnly(SaveLocati on)
'dSet.ReadXml("c:\inetpub\ wwwroot\As sessment\T emplates\o ut.xml", System.Data.XmlReadMode.Au to)
'UpdateAssessmentDetails(d Set)
'Response.Redirect("Assess mentHome.a spx", False)
Catch ex As Exception
Throw New Exception(ex.Message.ToStr ing())
End Try
End Sub
User has uploaded a file and i have saved it into SERVER in a predefined folder whose path is in "SaveLocation" variable.
Private Sub btnUpload_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpload.Click
REM Upload File
REM Update Database
Dim blUpdate As Boolean
Dim SaveLocation As String
Dim objXSLT As New XslTransform
Dim dSet As New DataSet
Dim i, j As Integer
Try
If Not File1.PostedFile Is Nothing And File1.PostedFile.ContentLe
Dim fn As String = System.IO.Path.GetFileName
SaveLocation = Server.MapPath("Templates"
Try
File1.PostedFile.SaveAs(Sa
Response.Write("The file has been uploaded.")
Catch Exc As Exception
Response.Write("Error: " & Exc.Message)
End Try
Else
Response.Write("Please select a file to upload.")
End If
'Transform the Document / XML file into PURE XML DATA ONLY FILE
''Create a new XslTransform object.
Dim xslt As New XslTransform
''''Load the stylesheet.
xslt.Load(CType("c:\inetpu
''''Create a new XPathDocument and load the XML data to be transformed.
Dim mydata As New XPathDocument(SaveLocation
Dim resolver As XmlUrlResolver = New XmlUrlResolver
resolver.Credentials = System.Net.CredentialCache
''''Transform the data and send the output to the console.
xslt.Transform(SaveLocatio
'Read this XML and put data into dataset
'SaveAsDataOnly(SaveLocati
'dSet.ReadXml("c:\inetpub\
'UpdateAssessmentDetails(d
'Response.Redirect("Assess
Catch ex As Exception
Throw New Exception(ex.Message.ToStr
End Try
End Sub
Have you stepped through with the debugger to check that the Xml and Xsl loaded ok ? The actual transform itself appears to be ok in my sample app.
ASKER
the out.xml is coming up with Root Tag so I don't think XSLT is not applied properly.
During debug all is fine.
My only worry is somehow XSLT file is not able to read through the rest of the NODES/MARKUPS in the template IN THIS APPROACH.
may be I need to carry on this issue.
During debug all is fine.
My only worry is somehow XSLT file is not able to read through the rest of the NODES/MARKUPS in the template IN THIS APPROACH.
may be I need to carry on this issue.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.