943,962 Members | Top Members by Rank

Ad:
Apr 6th, 2005
0

XSLT code doesn't seem to work!!

Expand Post »
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?
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
krishnakr is offline Offline
1 posts
since Apr 2005
May 5th, 2005
0

Re: XSLT code doesn't seem to work!!

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)
  1. <?xml version="1.0" ?>
  2. <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  3. <xsl:template match="/">
  4. <root_node>
  5. <xsl:apply-templates select="*" mode="result_nodes"/>
  6. </root_node>
  7. </xsl:template>
  8.  
  9. <xsl:template match="*" mode="result_nodes">
  10. <result_node>
  11. <xsl:apply-templates select="*" mode="result_nodes"/>
  12. </result_node>
  13. </xsl:template>
  14. </xsl:stylesheet>
Reputation Points: 20
Solved Threads: 5
Junior Poster
alpha_foobar is offline Offline
182 posts
since May 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Next Thread in XML, XSLT and XPATH Forum Timeline: How are you making use of xml?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC