Click here to Skip to main content
15,884,099 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,

Newbie to vb so please be gentle....

I am trying to transform some xml using xslcompliedtransform and the xsltargumentlist to another xml file. The file is created, but with only a root element

The main projects.xml file is loaded into a data grid view with some basic details, once a row is clicked, i want to filter the main xml file to create a html report containing all the xml data for the selected entry.

Obviously, not the full correct xml, but is an edited structure...

XML
<?xml version="1.0" encoding="UTF-8"?>
<Root>
	<Row A1="123456">
		<F48>Open</F48>
		<F49>Project One</F49>
	</Row>
	<Row A1="654321">
		<F48>Open</F48>
		<F49>Project One A</F49>
	</Row>
	<Row A1="223344">
		<F48>Closed</F48>
		<F49>Project Two</F49>
	</Row>
</Root>


The XSL being used:

XML
<?xml version="1.0" encoding="UTF-8"?> 
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes" />
<xsl:decimal-format name="NN" NaN="0" />
<xsl:param name="ID" />
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="/@* | node()" />
</xsl:copy>
</xsl:template>
<xsl:template match="Root">
<xsl:copy>
<xsl:apply-templates select="Row[@A1=$ID]" />
</xsl:copy>
</xsl:template>
<xsl:template match="Row">
<Row>
<xsl:apply-templates select="@A1 | F49 | F48" />
</Row>
</xsl:template>
</xsl:stylesheet>



The vb code running on a button click is

VB
Dim oXSL As New XslCompiledTransform()
oXSL.Load("findProject.xsl")
Dim oXslArg As New XsltArgumentList()
oXslArg.AddParam("ID", "", dgList.Rows(e.RowIndex).Cells(0).Value
oXSL.Transform(New XPathDocument("projects.xml"), XmlWriter.Create(dgList.Rows(e.RowIndex).Cells(0).Value & ".xml"))



The file that is created is

XML
<?xml version="1.0" encoding="utf-8"?><Root />



When running the transformation in XML Notepad or other xml editor, the transform works perfectly....any ideas people? Or any suggestions for a better method?

Many thanks

Graham
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900