xsl-list
[Top] [All Lists]

schema for translation of xml'ised spreadsheets

2003-11-18 10:25:35
hi, working on an xslt to transform one xml 2d matrix into another. thanks to your previous assistance, i have one transform that deletes, copies, renames, and generates fields (please see below) .

i now need to map values (i suspect that this is a big xsl:choose of some sort). but i would like to generate the xslt programmatically depending on how the luser fills out an html form. in general, it looks like i am transforming one 2d matrix into another and wondered if this type of thing had been done before.

it seems to me that i should invent a dtd or schema for a definition of the translation somewhat as follows:

<transform default="copy"> <!-- might be delete? -->
        <rules>
                <rename oldColumnName="old" newColumnName="new"/>
                <copy columnName="columnToBeCopied"/>
                <delete columnName="columnToBeDeleted"/>
                <generateRecord triggerColumnName="special1">
                        <newColumn name="newColumName1" value1="field1Value"/>
                        <newColumn name="newColumName2" value2="field2Value"/>
<newColumn name="newColumName3" /> <!-- value not defined means copy the field? -->
                </generateRecord>
                <map columnName="columnToBeMapped>
                        <pair in="inputValue1" out="outputValue1">
                        ...
                        <pair in="inputValue42" out="outputValue42">
                </map>
        </rules>

</transform>

it would seem then that i could read this with jdom and generate the appropriate xslt (like the one below).

any pointers or advice will be appreciated.

thanks

<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
        <xsl:strip-space elements="*"/>
        <xsl:output method="xml" indent="yes"/>
        <xsl:template match="/inputRows">
                <outputRows><xsl:apply-templates/></outputRows>
        </xsl:template>
        <xsl:template match="/inputRows/inputRow">
                <xsl:for-each select="child::*">
                        <xsl:if test="name()='special1' or name()='special2'">
                                <xsl:apply-templates select="."/>
                        </xsl:if>
                </xsl:for-each>
        </xsl:template>
        <xsl:template match="/inputRows/inputRow/special1">
                <xsl:call-template name="generateOutputRecord">
<xsl:with-param name="value1" select="'new1ValueFromSpecial1Name'"/> <xsl:with-param name="value2" select="'new2ValueFromSpecial1Name'"/>
                </xsl:call-template>
        </xsl:template>
        <xsl:template match="/inputRows/inputRow/special2">
                <xsl:call-template name="generateOutputRecord">
<xsl:with-param name="value1" select="'new1ValueFromSpecial2Name'"/> <xsl:with-param name="value2" select="'new2ValueFromSpecial2Name'"/>
                </xsl:call-template>
        </xsl:template>
        <xsl:template name="generateOutputRecord">
                <xsl:param name="value1" select="defaultValue1"/>
                <xsl:param name="value2" select="defaultValue2"/>
                <outputRow>
                <inputRecordSequenceNumber>
                <xsl:number count="inputRow"/>
                </inputRecordSequenceNumber>
                <xsl:for-each select="../*">
                        <xsl:call-template name="processField"/>
                </xsl:for-each>
                <xsl:call-template name="addNewFields">
                        <xsl:with-param name="value1" select="$value1"/>
                        <xsl:with-param name="value2" select="$value2"/>
                </xsl:call-template>
                </outputRow><xsl:text/>
        </xsl:template>
        <xsl:template name="addNewFields">
                <xsl:param name="value1" select="defaultValue1"/>
                <xsl:param name="value2" select="defaultValue2"/>
<xsl:element name="new1"><xsl:value-of select="$value1"/></xsl:element> <xsl:element name="new2"><xsl:value-of select="$value2"/></xsl:element> <xsl:element name="new3"><xsl:value-of select="."/></xsl:element>
        </xsl:template>
        <xsl:template name="processField">
                <xsl:choose>
                        <xsl:when test="name()='special1'"></xsl:when>
                        <xsl:when test="name()='special2'"></xsl:when>
                        <xsl:when test="name()='remove1'"></xsl:when>
                        <xsl:when test="name()='copy1'">
                                <xsl:element name="{name()}">
                                        <xsl:value-of select="."/>
                                </xsl:element>
                        </xsl:when>
                        <xsl:when test="name()='rename1'">
                                <xsl:element name="renamed1">
                                        <xsl:value-of select="."/>
                                </xsl:element>
                        </xsl:when>
                </xsl:choose>
        </xsl:template>
</xsl:stylesheet>
---

ray tayek http://tayek.com/ actively seeking mentoring or telecommuting work
vice chair orange county java users group http://www.ocjug.org/
hate spam? http://samspade.org/ssw/


XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list



<Prev in Thread] Current Thread [Next in Thread>
  • schema for translation of xml'ised spreadsheets, Ray Tayek <=