p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


  Return to Index  

vb_xml thread: group records from a xml file


Message #1 by "yeong" <hkyeong1@y...> on Fri, 7 Feb 2003 08:26:49
hi all:

I have the following xml file:
(a1.xml)

<?xml version="1.0" ?> 
<external_links>	
<link>
	<site_name>site1</site_name>
	<category_name>Category 1</category_name>
</link>
<link>
	<site_name>site2</site_name>
	<category_name>Category 2</category_name>
</link>
<link>
	<site_name>site3</site_name>
	<category_name>Category 1</category_name>
</link>
<link>
	<site_name>site4</site_name>
	<category_name>Category 2</category_name>
</link>
</external_links>	


I have the following xsl file:
(t1.xsl)

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
version="1.0">

<xsl:key name="links-by-category" match="link" use="category_name" />

<xsl:template match="external_links">
	<xsl:for-each select="//link[count(. | key('links-by-category',
category_name)[1]) = 1]">
		<xsl:sort select="category_name" />
		<xsl:value-of select="category_name" /><br />
		<xsl:for-each select="key('links-by-category',
category_name)">
			<xsl:sort select="site_name" />
			<xsl:value-of select="site_name" /> <br />
		</xsl:for-each>
	</xsl:for-each>

<xsl:apply-templates />
</xsl:template>
</xsl:stylesheet>


in vb code

Private Sub Command7_Click()
Set source1 = CreateObject("microsoft.xmldom")
source1.async = False
source1.Load (App.Path & "\a1.xml")


Set dynstyle = CreateObject("microsoft.xmldom")
dynstyle.async = False
dynstyle.Load (App.Path & "\t1.xsl")
MsgBox dynstyle.parseError.errorCode

q = source1.transformNode(dynstyle)
'MsgBox q

szfile = App.Path & "\sample.xml"
Set ofso = CreateObject("Scripting.FileSystemObject")
Set ofile = ofso.OpenTextFile(szfile, 2)
ofile.write (q)
ofile.Close

'MsgBox "done22"


End Sub


my question 

1)why the sample.xml file
is alway come out same as t1.xsl

2)cannot get the format in sample.xml like

Expected out:

Category 1
-----------
site1
site3

Category 2
-----------
site2
site4


**in xml format??

thank for advance

regard,
yeong


  Return to Index