[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Correlation between two xml trees

Subject: Correlation between two xml trees
From: John Sands <WonkoWatson@xxxxxxxxx>
Date: Wed, 5 Jun 2002 23:35:08 -0400
xml correlation
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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.