Altova Mailing List Archives>Archive Index >microsoft.public.xsl Archive Home >Recent entries >Thread Prev - Re: Grouping nodes into new resultset? [Thread Next] Re: Grouping nodes into new resultset?To: NULL Date: 12/7/2004 12:49:00 PM Here is the .NET code that I mentioned in the previous post:
private XmlDocument TransformDataSet(string XsltDocumentName, DataSet dst)
{
XmlDocument xmldoc = new XmlDocument();
XmlDataDocument xmldd = new XmlDataDocument(dst);
XslTransform transform = new XslTransform();
transform.Load(Server.MapPath(XsltDocumentName));
XmlReader reader = transform.Transform(xmldd, null, new XmlUrlResolver());
xmldoc.Load(reader); <-- ERROR! - null object reference here...
return xmldoc;
}
"Dave" wrote:
> Oleg,
>
> Here's what I have so far working in XSelerator utility using both MSXML 3 &
> 4 transform engines. The XML, XSL, and the result is below. However, in my
> .NET Transform it bombs with "Object reference not set to an instance of an
> object" when I try to transform and load it into an XmlDocument. Is there
> anything I can do?
>
> XML:
> ----
> <NewDataSet>
> <row>
> <CompanyId>676708</CompanyId>
> <CompanyName>Microsoft Corporation</CompanyName>
> <CountryCd>US</CountryCd>
> <CodeId>20</CodeId>
> <CodeName>AAAA</CodeName>
> </row>
> <row>
> <CompanyId>676708</CompanyId>
> <CompanyName>Microsoft Corporation</CompanyName>
> <CountryCd>US</CountryCd>
> <CodeId>21</CodeId>
> <CodeName>BBBB</CodeName>
> </row>
> <row>
> <CompanyId>676708</CompanyId>
> <CompanyName>Microsoft Corporation</CompanyName>
> <CountryCd>US</CountryCd>
> <CodeId>22</CodeId>
> <CodeName>CCCCCC</CodeName>
> </row>
> <row>
> <CompanyId>676708</CompanyId>
> <CompanyName>Microsoft Corporation</CompanyName>
> <CountryCd>US</CountryCd>
> <CodeId>23</CodeId>
> <CodeName>DDDDD</CodeName>
> </row>
> </NewDataSet
>
> XSL:
> ----
> <?xml version="1.0" ?>
> <xsl:stylesheet version="1.0"
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
>
> <!-- Define keys used to group elements -->
> <xsl:key name="keyCompanyId" match="row" use="CompanyId" />
>
> <xsl:template match="NewDataSet">
> <companycodelist>
> <xsl:for-each select="//row[generate-id(.) =
> generate-id(key('keyCompanyId', CompanyId)[1])]">
> <xsl:variable name="lngCompanyId"><xsl:value-of select="CompanyId"
> /></xsl:variable>
> <xsl:variable name="lstRow" select="//row[CompanyId=$lngCompanyId]" />
> <xsl:call-template name="ShowCompanyCodes">
> <xsl:with-param name="lstRow" select="$lstRow" />
> </xsl:call-template>
> </xsl:for-each>
> </companycodelist>
> </xsl:template>
>
> <xsl:template name="ShowCompanyCodes">
> <xsl:param name="lstRow" />
>
> <company>
> <companyname><xsl:value-of select="$lstRow[1]/CompanyName"
> /></companyname>
> <codes>
> <xsl:for-each select="$lstRow">
> <xsl:element name="code">
> <xsl:attribute name="id"><xsl:value-of select="CodeId"/></xsl:attribute>
> <xsl:attribute name="name"><xsl:value-of
> select="CodeName"/></xsl:attribute>
> <xsl:value-of select="CodeValue" />
> </xsl:element>
> </xsl:for-each>
> </codes>
> </company>
> </xsl:template>
>
> </xsl:stylesheet>
>
>
> Result:
> -------
> <?xml version="1.0" encoding="UTF-16"?>
> <companycodelist>
> <company>
> <companyname>Microsoft Corporation</companyname>
> <codes>
> <code id="20" name="AAAA"></code>
> <code id="21" name="BBBB"></code>
> <code id="22" name="CCCCCC"></code>
> <code id="23" name="DDDDD"></code>
> </codes>
> </company>
> </companycodelist>
>
>
>
>
>
>
>
>
> "Oleg Tkachenko [MVP]" wrote:
>
> > Dave wrote:
> >
> > > <?xml version="1.0" ?>
> > > <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
> > > version="2.0">
> >
> > You seems to be using XSLT 2.0? Beware neither MSXML nor .NET support
> > XSLT 2.0.
> >
> > > <xsl:template match="NewDataSet" mode="grp_company">
> > > <NewDataSet>
> > > <xsl:for-each select="row[generate-id() =
> > > generate-id(key('company_key', CompanyName)[1])]">
> >
> > Well, where is a definition for the company_key ?
> > Can you provide more complete XSLT stylesheet?
> > --
> > Oleg Tkachenko [XML MVP]
> > http://blog.tkachenko.com
> >
| ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
