![]() |
![]() | ![]() | ![]() | Altova Mailing List Archives>Archive Index >microsoft.public.xsl Archive Home >Recent entries >Thread Prev - Re: Why would encoding="UTF-8" chance to "UTF=16"? >Thread Next - Re: Why would encoding="UTF-8" chance to "UTF=16"? Re: Why would encoding="UTF-8" chance to "UTF=16"?To: NULL Date: 7/20/2007 1:39:00 PM
Good,
Here is one of the code I am using to transform the file. The other one
also use MSXML.DOMDocument and I have tried both. I found both on the
Internet.
I hope this helps.
Thank you.
Hennie
Sub xml4()
Dim xmlSource
Dim xmlXForm
Dim strErr
Dim strResult
Dim fso, file
Dim strPath
Const ForWriting = 2
Set xmlSource = CreateObject("MSXML.DOMDocument")
Set xmlXForm = CreateObject("MSXML.DOMDocument")
xmlSource.validateOnParse = True
xmlXForm.validateOnParse = True
xmlSource.async = False
xmlXForm.async = False
'initializing, and creating the objects to load our XML and XSL files needed
in the next step:
' This loads the text that I want to transform
xmlSource.Load "H:\Chem\DATA\XML Report\sample.xml"
If Err.Number <> 0 Then
strErr = Err.Description & vbCrLf
strErr = strErr & xmlSource.parseError.reason & " line: " & _
xmlSource.parseError.Line & " col: " & _
xmlSource.parseError.linepos & _
" text: " & xmlSource.parseError.srcText
MsgBox strErr, vbCritical, "Error loading the XML"
End If
' This loads the XSLT transform
'Here you need to update your Xsl file
'xmlXForm.Load "Your XSL file Path"
' This loads the XSLT transform
xmlXForm.Load "H:\Chem\DATA\XML Report\mews.xsl"
If Err.Number <> 0 Then
strErr = Err.Description & vbCrLf
strErr = strErr & xmlSource.parseError.reason & " line: " & _
xmlSource.parseError.Line & " col: " & _
xmlSource.parseError.linepos & _
" text: " & xmlSource.parseError.srcText
MsgBox strErr, vbCritical, "Error loading the Transform"
End If
'This tells the XML objects to load the files into memory for the transform
which we perform next:
' This transforms the data in xmlSource
strResult = xmlSource.transformNode(xmlXForm)
If Err.Number <> 0 Then
strErr = Err.Description & vbCrLf
strErr = strErr & xmlSource.parseError.reason & _
" line: " & xmlSource.parseError.Line & _
" col: " & xmlSource.parseError.linepos & _
" text: " & xmlSource.parseError.srcText
MsgBox strErr, vbCritical, "Error executing the Transform"
End If
'At this point, the transformed XML is placed into a string variable called
strResult that we need to write as file to disk:
Set fso = CreateObject("Scripting.FileSystemObject")
'Here you need to update your Output files
strPath = "H:\Chem\DATA\XML Report\result.xml"
' open the file
Set file = fso.opentextfile(strPath, ForWriting, True)
' write the info to the file
file.Write strResult
End Sub
"Anthony Jones" <Ant@y...> wrote in message
news:eAxlfSEyHHA.484@T......
>
>
> "Hennie" <ze1@h...> wrote in message
> news:u%Tmi.39242$KV1.23035@r......
>>
>>
>> Good Day,
>> I have the XSL style sheet attached below. Whenever I do a
>> transformation
>> of an XML file the "UTF= 8" enconding is always changed to "UTF = 16".
>> Before I can use the transformed file I need to Edit it in Notepad. The
>> rest of the transformed file works as a charm. I assume it is something
>> small but I know to little to solve the problem.
>>
>> Thank you for your time.
>>
>> Hennie
>>
>>
>> <xsl:stylesheet
>> xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" >
>>
>> <xsl:output method="xml" indent="yes"/>
>>
>> <!-- the key determines (here) what to group by -->
>> <xsl:key name="sample" match="sample" use="concat(sample_date_time,
>> cp_name, imis_cp_ext, dischg_sample_cd, sample_comment)" />
>>
>> <xsl:template match="/">
>> <submission imis_company_code="0001843309" ws_name="ONTARIO POWER
>> GENERATION INC. - LENNOX GS">
>> <xsl:apply-templates />
>> </submission>
>>
>> </xsl:template>
>> <xsl:template match="dataroot">
>> <!-- the actual 'group by' construct -->
>> <xsl:for-each select="sample[generate-id() =
>> generate-id(key('sample',concat(sample_date_time, cp_name, imis_cp_ext,
>> dischg_sample_cd, sample_comment))[1])]">
>> <xsl:copy>
>> <!-- date-time must become an attribute -->
>> <xsl:apply-templates select="sample_date_time | cp_name |
>> imis_cp_ext | dischg_sample_cd | sample_comment"/>
>>
>> <!-- find all samples with equal date time -->
>> <xsl:apply-templates select="key('sample',
>> concat(sample_date_time, cp_name, imis_cp_ext, dischg_sample_cd,
>> sample_comment))" />
>> </xsl:copy>
>> </xsl:for-each>
>> </xsl:template>
>> <!-- match the sample's that are grouped -->
>> <xsl:template match="sample">
>> <result>
>>
>> <xsl:apply-templates select="*[not(self::sample_date_time or
> self::cp_name
>> or self::imis_cp_ext or self::dischg_sample_cd or self::sample_comment)]"
>> />
>>
>> </result>
>> </xsl:template>
>>
>> <!-- any direct child of 'sample' must be turned into an attribute -->
>> <xsl:template match="sample/*">
>> <xsl:attribute name="{name()}">
>> <xsl:value-of select="."/>
>> </xsl:attribute>
>> </xsl:template>
>>
>>
>
> It might be more helpful if you post the code that executes and saves the
> transforms results.
>
> --
> Anthony Jones - MVP ASP/ASP.NET
>
>
| ![]() | ![]() | ![]() |
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | |||||
|
