Subject: [xsl] RE: Transformation XML to XML From: "Rob Merrison" <rob.merrison@xxxxxxxxxxxx> Date: Tue, 19 Jul 2005 10:31:58 +0100 |
Hi I need some help please with the following xslt stylesheet. I use this style sheet that gets pulled into the ASP file after the query is run on an ACCESS database. The output is xml. However the xml is not formed to the correct layout. This file is called ADOGeneric.xsl and is referenced in the ASP file. <?xml version='1.0'?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:s="uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882" xmlns:z="#RowsetSchema"> <s:Schema id="RowsetSchema"/> <xsl:output method="xml" omit-xml-declaration="yes" /> <xsl:template match="/"> <xsl:apply-templates select="//z:row"/> </xsl:template> <xsl:template match="z:row"> <xsl:text disable-output-escaping="no"><image></xsl:text> <xsl:for-each select="@*"> <xsl:text disable-output-escaping="no"><</xsl:text> <xsl:value-of select="name()"/> <xsl:text disable-output-escaping="no">></xsl:text> <xsl:value-of select="."/> <xsl:text disable-output-escaping="no"></</xsl:text> <xsl:value-of select="name()"/> <xsl:text disable-output-escaping="no">></xsl:text> </xsl:for-each> <xsl:text disable-output-escaping="no"></image></xsl:text> </xsl:template> </xsl:stylesheet> <%@ Language = VBScript %> <% Response.Expires = -1 Response.Buffer = True Dim conn, rs, xml, xsl Set conn = Server.CreateObject("ADODB.Connection") conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("gen_dib_data.mdb") & ";User Id=admin;Password=;" conn.Open Set rs = Server.CreateObject("ADODB.Recordset") Set rs.ActiveConnection = conn rs.Open "SELECT Photo.PDesc, Photo.Filename, Photo.PhotoID, Photo.PhotogID FROM Photo" alldata=rs.getrows() numcols=ubound(alldata,1) numrows=ubound(alldata,2) Set xml = Server.CreateObject("MSXML2.DOMDocument") Set xsl = Server.CreateObject("MSXML2.DOMDocument") xml.async = False xsl.async = False rs.Save xml, 1 'adPersistXML xsl.load Server.MapPath("ADOGeneric.xsl") Response.Write(lcase(xml.transformNode(xsl))) Set xsl = Nothing Set xml = Nothing rs.Close Set rs = Nothing conn.Close Set conn = Nothing %> The output currently looks like this, one continuous line: <image><pdesc>hot rod</pdesc><filename>ab_0001.jpg</filename><photoid>223</photoid><photogid>5 </photogid></image><image><pdesc>brass headlamps</pdesc><filename>ab_0002.jpg</filename><photoid>224</photoid><phot ogid>5</photogid></image> which I guess if I split it up it would look like this: <image> <pdesc>hot rod</pdesc> <filename>ab_0001.jpg</filename> <photoid>223</photoid> <photogid>5</photogid> </image> <image> <pdesc>brass headlamps</pdesc> <filename>ab_0002.jpg</filename> <photoid>224</photoid> <photogid>5</photogid> </image> I actually need an xslt script to produce the output to look like the following if this is possible with the added element collection: <collection> <image pdesc="hot rod" filename="ab_0001.jpg" photoid="223" photogid="5"/> <image pdesc="brass headlamps" filename="ab_0002.jpg" photoid="224" photogid="5"/> </collection> I tried this in order to achieve the results but this fails with the message below and I'm pretty sure this is almost correct. <?xml version='1.0'?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/"> <xsl:element name="collection"> <xsl:for-each select="/collection/image" > <xsl:element name='{name()}'> <xsl:for-each select="*" > <xsl:attribute name='{name()}'> <xsl:value-of select="."/> </xsl:attribute> </xsl:for-each> </xsl:element> </xsl:for-each> </xsl:element> </xsl:template> </xsl:stylesheet> The XML page cannot be displayed Cannot view XML input using style sheet. Please correct the error and then click the Refresh button, or try again later. ---------------------------------------------------------------------------- ---- Switch from current encoding to specified encoding not supported. Error processing resource 'http://thebes/ImageRealm_new_1... <?xml version="1.0" encoding="utf-16"?><collection></collection> ---------------------------------------^ many thanks Rob.
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] Generating User Interface, Angel Gavin | Thread | RE: [xsl] RE: Transformation XML to, Michael Kay |
Re: [xsl] Problem with Formatting a, Mukul Gandhi | Date | [xsl] Problem with Formatting a str, Lakshmi narayana |
Month |