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

Re: transforming xml to tables

Subject: Re: transforming xml to tables
From: Niclas Hedhman <niclas@xxxxxxxxxxx>
Date: Wed, 16 Jun 2004 15:15:01 +0800
xml to tables
On Tuesday 15 June 2004 00:41, Pedro Castro wrote:
> Hi, all. I'm a beginner in this xsl world and I'm trying to learn.
> I could do the work I have to do in a different way but I'm trying to see
> the advantages of xsl (which are convincing me). But I was stopped in the
> process because of a problem which I (try to) describe next:

You need two XSL passes, generating one file for each pass.

The first one is very simple, as you take the 'same suff' strip out some 
attributes and check a string containing the _ID at the end...

<xsl:template match="aaa" >
  <table>
    <xsl:attribute name="name">
      <xsl:value-of select="@name" />
    </xsl:attribute>
    <xsl:apply-templates />
  </table>
</xsl:template>

<xsl:template match="bbb" >
  <column>
    <xsl:attribute name="name">
      <xsl:value-of select="@name" />
    </xsl:attribute>
    <xsl:if test="contains( @name, '_ID' )" >
      <xsl:attribute name="primaryKey">true</xsl:attribute>
    </xsl:if>
  </column>
</xsl:template>


The second phase is handled roughly the manner...

<xsl:template match="aaa/bbb[ @type = 't2'] " >
  <table>
    <xsl:attribute name="name">
      <xsl:value-of select="../@name" />
    </xsl:attribute>
<!-- You need to extract the pieces you want to generate the required result 
here. I'm barely awake to follow your intentions, and this section will get a 
little bit 'tricky', so some trial and error will help, but basically no 
template matching/applying should be used. -->
  </table>
</xsl:template>


Hope that help as a start...

Cheers
Niclas


> I have the following xml:
>
> <aaa name="t1">
> 	<bbb name="t1_ID" type="n"/>
> 	<bbb name="c1" type="t2"/>
> 	<bbb name="c2"/>
> 	<bbb name="c3" type="n"/>
> </aaa>
>
> And I want to transform this (part) into a script for create a relational
> table structure (for later processing):
>
> (A table has always an id that is conventioned to be the table name
> followed by "_ID" word)
>
> <table name="t1">
> 	<column name="t1_ID" primaryKey="true"/>
> 	<column name="c1"/>
> 	<column name="c2"/>
> 	<column name="c3"/>
> </table>
>
> <table name="t1_t2_nxn">
> 	<column name="t1_ID" primaryKey="true"/>
> 	<column name="t2_ID" primaryKey="true"/>
> 	<foreign-key foreignTable="t1">
> 		<reference local="t1_ID" foreign="t1_ID"/>
> 	</foreign-key>
> 	<foreign-key foreignTable="t2">
> 		<reference local="t2_ID" foreign="t2_ID"/>
> 	</foreign-key>
> </table>
>
>
> The rules for transformation are simple: if an inner element for the <aaa>
> element has a type other than none or "n" (like the type="t2" case) than i
> need to create the second table which is an n x n table between t1 and (an
> already existent) t2 table.
>
> Is this possible to do in xsl?
> I'm sorry for the long question, and I hope that anybody can understand and
> help :)
>
> Thanks in advance!!
>
>
> Pedro Castro.
> Portugal.
>
>
>
> --+------------------------------------------------------------------
> XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
> To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
> or e-mail: <mailto:xsl-list-unsubscribe@xxxxxxxxxxxxxxxxxxxxxx>
> --+--

-- 
   +------//-------------------+
  / http://www.bali.ac        /
 / http://niclas.hedhman.org / 
+------//-------------------+


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.