Subject: [xsl] Correlation between two xml trees From: John Sands <WonkoWatson@xxxxxxxxx> Date: Wed, 5 Jun 2002 23:35:08 -0400 |
I'm sorry I can't come up with a short description of what I want to do. Instead, here is an example. I have an exported recordset (henceforth known as tabledef) that looks like this: <xml xmlns:rs='urn:schemas-microsoft-com:rowset' xmlns:z='#RowsetSchema'> <rs:data> <z:row col1='1' col2='a' col3='x' /> <z:row col1='2' col2='b' col3='y' /> <z:row col1='3' col2='c' col3='z' /> </rs:data> </xml> and another xml document (outputdef) that looks like this: <root> <column tagname="tag1" dbcolumn="col1"/> <column tagname="tag2" dbcolumn="col2"/> </root> I want to output this: <root> <data> <tag1>1</tag1> <tag2>a</tag2> </data> <data> <tag1>2</tag1> <tag2>b</tag2> </data> <data> <tag1>3</tag1> <tag2>c</tag2> </data> </root> In other words, I want to output a "data" element for each row in tabledef and I want to use the element values from tabledef, but I want to output only the elements defined with "dbcolumn" attributes in outputdef and I want to use the element names from outputdef. I've got the structure correct, but no values. Like this: <root> <data> <tag1></tag1> <tag2></tag2> </data> <data> <tag1></tag1> <tag2></tag2> </data> <data> <tag1></tag1> <tag2></tag2> </data> </root> I'm using MSXML4. Here is my XSLT (I'm transforming the tabledef; the outputdef is being passed in as a DOMDocument parameter): <?xml version="1.0"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:rs='urn:schemas-microsoft-com:rowset' xmlns:z='#RowsetSchema' version="1.0"> <xsl:output method="xml" indent="yes" /> <xsl:param name="outputdef" /> <xsl:template match="/"> <root> <xsl:apply-templates select="/xml/rs:data/z:row"/> </root> </xsl:template> <xsl:template match="z:row"> <data> <xsl:for-each select="$outputdef/root/column"> <xsl:element name="{@tagname}"> --------> SOME MAGIC HAPPENS HERE <---------- </xsl:element> </xsl:for-each> </data> </xsl:template> </xsl:stylesheet> How do I get the value from the outer z:row context that corresponds to the dbcolumn attribute for the current $outputdef/root/column? Thanks, John XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] Cant see params passed to, Avula, Raj | Thread | Re: [xsl] Correlation between two x, Joerg Heinicke |
RE: [xsl] Cant see params passed to, Avula, Raj | Date | [xsl] xslt file correction, normbishop1 |
Month |