| | |
XSLT code doesn't seem to work!!
Please support our XML, XSLT and XPATH advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Apr 2005
Posts: 1
Reputation:
Solved Threads: 0
I am new to XML/XSLT and have taken a fascination to XSLT.
Please take a look at the following and let me know.
==========================================================
<?xml version="1.0"?>
<FAMILY>
<PERSON name="Freddy"/>
<PERSON name="Maartje"/>
<PERSON name="Gerard"/>
<PERSON name="Peter"/>
<PET name="Bonzo" type="dog"/>
<PET name="Arnie" type="cat"/>
</FAMILY>
This file is saved as family.xml
==========================================================
<?xml version="1.0" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/xsl/transform" version="1.0">
<xsl:template match="/">
<root_node>
<xsl:apply-templates/>
</root_node>
</xsl:template>
<xsl:template match="*">
<result_node>
<xsl:apply-templates/>
</result_node>
</xsl:template>
</xsl:stylesheet>
This file is saved as test.xsl
==========================================================
Dim oDoc As DOMDocument
Dim oXSLT As DOMDocument
Dim sResult As String
Dim sPath As String
Set oDoc = New DOMDocument
Set oXSLT = New DOMDocument
oDoc.async = False
oXSLT.async = False
oDoc.Load txtSource.Text
oXSLT.Load txtTransformer.Text
sResult = oDoc.transformNode(oXSLT)
Set fso = New Scripting.FileSystemObject
sPath = fso.BuildPath("C:\VB\XML\", "Dest.xml")
fso.CreateTextFile sPath
Set ts = fso.OpenTextFile(sPath, ForWriting)
ts.Write sResult
ts.Close
Set ts = Nothing
Set fso = Nothing
Set oDoc = Nothing
Set oXSLT = Nothing
In my VB IDE the project references MSXML v4.0
This code should be very self-explanatory.
==============================================================
My problem:
The code generates the result file, but is a copy of the xsl file minus the xml PI.
It is supposed to generate the following:
<root_node>
<result_node>
<result_node/>
<result_node/>
<result_node/>
<result_node/>
<result_node/>
<result_node/>
</result_node>
</root_node>
What am I doing wrong?
Please take a look at the following and let me know.
==========================================================
<?xml version="1.0"?>
<FAMILY>
<PERSON name="Freddy"/>
<PERSON name="Maartje"/>
<PERSON name="Gerard"/>
<PERSON name="Peter"/>
<PET name="Bonzo" type="dog"/>
<PET name="Arnie" type="cat"/>
</FAMILY>
This file is saved as family.xml
==========================================================
<?xml version="1.0" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/xsl/transform" version="1.0">
<xsl:template match="/">
<root_node>
<xsl:apply-templates/>
</root_node>
</xsl:template>
<xsl:template match="*">
<result_node>
<xsl:apply-templates/>
</result_node>
</xsl:template>
</xsl:stylesheet>
This file is saved as test.xsl
==========================================================
Dim oDoc As DOMDocument
Dim oXSLT As DOMDocument
Dim sResult As String
Dim sPath As String
Set oDoc = New DOMDocument
Set oXSLT = New DOMDocument
oDoc.async = False
oXSLT.async = False
oDoc.Load txtSource.Text
oXSLT.Load txtTransformer.Text
sResult = oDoc.transformNode(oXSLT)
Set fso = New Scripting.FileSystemObject
sPath = fso.BuildPath("C:\VB\XML\", "Dest.xml")
fso.CreateTextFile sPath
Set ts = fso.OpenTextFile(sPath, ForWriting)
ts.Write sResult
ts.Close
Set ts = Nothing
Set fso = Nothing
Set oDoc = Nothing
Set oXSLT = Nothing
In my VB IDE the project references MSXML v4.0
This code should be very self-explanatory.
==============================================================
My problem:
The code generates the result file, but is a copy of the xsl file minus the xml PI.
It is supposed to generate the following:
<root_node>
<result_node>
<result_node/>
<result_node/>
<result_node/>
<result_node/>
<result_node/>
<result_node/>
</result_node>
</root_node>
What am I doing wrong?
Hi I did a minor change to your xsl and i think i got the result you are after:
XML, XSLT and XPATH Syntax (Toggle Plain Text)
<?xml version="1.0" ?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/"> <root_node> <xsl:apply-templates select="*" mode="result_nodes"/> </root_node> </xsl:template> <xsl:template match="*" mode="result_nodes"> <result_node> <xsl:apply-templates select="*" mode="result_nodes"/> </result_node> </xsl:template> </xsl:stylesheet>
![]() |
Similar Threads
- Search code in a database (Visual Basic 4 / 5 / 6)
- Code for Call the program in Visual Basic (Visual Basic 4 / 5 / 6)
- The following Code won't work, Plez help? (C++)
- javascript code not working in mozillafirefox (JavaScript / DHTML / AJAX)
- Plug and play code 10 problems (Troubleshooting Dead Machines)
Other Threads in the XML, XSLT and XPATH Forum
- Next Thread: How are you making use of xml?
| Thread Tools | Search this Thread |
api blogger blogging code delete development dynamiccreationofnvariablesinxslt error firstthreecharacterofastringrequired flipbook gdata google html include java link linspire linux microsoft news node openoffice overwrite precedence programming rss standards swf template transform variable w3c web xml xmlnotloading xmlonserver xsl xslt





