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

RE: Passing parameter into xsl:for-each

Subject: RE: Passing parameter into xsl:for-each
From: cknell@xxxxxxxxxx
Date: Mon, 16 Aug 2004 12:44:15 -0400
passing parameter to xsl
> -----Original Message-----
> From:     Ade Odusote <aodusote@xxxxxxxxxxx>
> Sent:     Mon, 16 Aug 2004 10:34:09 -0400
> To:       <xsl-list@xxxxxxxxxxxxxxxxxxxxxx>
> Subject:   Passing parameter into xsl:for-each
>
> I have an XML data dictionary which I am trying to use to create a SQL DDL statement. 
> The XML is below:

I second Andrew Welch's remark on the combination of push/pull. Once you are able to wrap your brain around push processing (admittedly hard to do for a person with a procedural programming background), you will find that they make XLST programming much easier.

The structure of your XML is ambiguous when it comes to deciding which data type to apply. For example, what is the data type of dictionary/columns/column[@name="COMP_CODE"]?
I assumed that it is VARCHAR2, but it could be VARCHAR or CHAR. Is RENW_STOR_PROF_CODE fixed or a float? Is VAR_LINE_ROOT_FLAG a byte or a char?

I made some assumptions on data typing, changed the output to "text", and switched to a push process to make this first cut approximation. See if you can take it from there.

<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="text" indent="yes" encoding="UTF-8" />

  <xsl:template match="/">
    <xsl:apply-templates />
  </xsl:template>

  <xsl:template match="tables">
    <xsl:apply-templates />
  </xsl:template>

  <xsl:template match="table">
    create table <xsl:value-of select="@name" />(
      <xsl:apply-templates select="column" />
    );
  </xsl:template>

  <xsl:template match="column">
    <xsl:variable name="this-col" select="@name" />
    <xsl:variable name="d-type">
      <xsl:choose>
        <xsl:when test="/dictionary/columns/column[@name=$this-col][@datatype='number']"> FLOAT(<xsl:value-of select="/dictionary/columns/column[@name=$this-col]/@length" />,<xsl:value-of select="/dictionary/columns/column[@name=$this-col]/@decimals" />)</xsl:when>
        <xsl:when test="/dictionary/columns/column[@name=$this-col][@datatype='date']"> DATE</xsl:when>
        <xsl:otherwise><xsl:value-of select="/dictionary/columns/column[@name=$this-col]/@datatype" /> VARCHAR2 <xsl:value-of select="/dictionary/columns/column[@name=$this-col]/@length" /></xsl:otherwise>
      </xsl:choose>
    </xsl:variable>
    <xsl:value-of select="@name" /> <xsl:value-of select="$d-type" />
    <xsl:if test="following-sibling::column">,</xsl:if>
  </xsl:template>

  <xsl:template match="columns" />
  <xsl:template match="columns/column" />

</xsl:stylesheet>

-- 
Charles Knell
cknell@xxxxxxxxxx - email

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.