DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: XSLT - Problems

  1. #1
    Davide Guest

    XSLT - Problems


    Hello,
    this problem is driven me crazy.
    I do have a sort of xml, and I need to transform it in another one.
    It is not a problem, but the structure of this one is not so clear.
    It is a table (2 col, 3 rows), but all records are in sequence with an ";"
    as separator. Is there any kind of function in xslt to manage this format...Thanks,
    in advance,
    davide



    <IFVariable name="WorkingTable" flags="4259841" version="1.3.39.0" type="table">{8;8}[2;3]111111;BL;222222;BL;333333;MM


    <IFMethod name="AddDispatchMethods" flags="66048" type="IFNativeMethod"/><IFComponent
    name="ColumnDescription" flags="65537" type="IFComponent"><IFVariable name="Column001"
    flags="65536" type="string"/><IFVariable name="Column002" flags="65536" type="string"/></IFComponent></IFVariable>

  2. #2
    Jason Sobell iGadget Guest

    Re: XSLT - Problems

    It's possible, but very very messy, and not what XSLT is designed to do.
    Look at the various string functions such as:
    substring
    substring-after
    substring-before
    string-length
    translate
    substring

    It would be a nightmare to implement though, so you are far better to
    preparse the data and convert these strings into tags and/or attributes.
    You are not performing XML transformation here, you are performing data
    transformation.

    Cheers,
    Jason

    On 7 Feb 2003 07:50:54 -0800, Davide wrote:

    >
    > Hello,
    > this problem is driven me crazy.
    > I do have a sort of xml, and I need to transform it in another one.
    > It is not a problem, but the structure of this one is not so clear.
    > It is a table (2 col, 3 rows), but all records are in sequence with an ";"
    > as separator. Is there any kind of function in xslt to manage this format...Thanks,
    > in advance,
    > davide
    >
    >
    >
    > <IFVariable name="WorkingTable" flags="4259841" version="1.3.39.0" type="table">{8;8}[2;3]111111;BL;222222;BL;333333;MM
    >
    >
    > <IFMethod name="AddDispatchMethods" flags="66048" type="IFNativeMethod"/><IFComponent
    > name="ColumnDescription" flags="65537" type="IFComponent"><IFVariable name="Column001"
    > flags="65536" type="string"/><IFVariable name="Column002" flags="65536" type="string"/></IFComponent></IFVariable>


  3. #3
    Tom Larson Jayhill Software Inc Guest

    Re: XSLT - Problems


    The following stylesheet will replace the node value with a group of cell
    nodes with row and column attributes. It is a little messy and there is
    probably an easier way to do it but this may give you some ideas.

    Good Luck, Tom

    <?xml version='1.0' encoding="ISO-8859-1"?>
    <xsl:stylesheet version='1.0' xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xslutput method="xml" version="1.0" encoding="ISO-8859-1" omit-xml-declaration="yes"/>

    <xsl:template match="IFVariable">
    <xsl:copy>
    <xsl:attribute name="name"><xsl:value-of select="@name"/></xsl:attribute>
    <xsl:attribute name="flags"><xsl:value-of select="@flags"/></xsl:attribute>
    <xsl:attribute name="version"><xsl:value-of select="@version"/></xsl:attribute>
    <xsl:attribute name="type"><xsl:value-of select="@type"/></xsl:attribute>
    <xsl:call-template name="parseRecords">
    <xsl:with-param name="curNode"><xsl:value-of select="node()"/></xsl:with-param>
    </xsl:call-template>
    </xsl:copy>
    </xsl:template>

    <xsl:template name="parseRecords">
    <xslaram name="curNode"><xsl:value-of select="curNode"/></xslaram>
    <xsl:variable name="source"><xsl:value-of select="string($curNode)"/></xsl:variable>
    <xsl:variable name="columns">
    <xsl:value-of select="substring(substring-after($source, '['), 1, 1)"/>
    </xsl:variable>
    <xsl:call-template name="addRecord">
    <xsl:with-param name="source"><xsl:value-of select="substring-after(string($source),
    ']')"/></xsl:with-param>
    <xsl:with-param name="columns"><xsl:value-of select="$columns"/></xsl:with-param>
    <xsl:with-param name="row">1</xsl:with-param>
    </xsl:call-template>
    </xsl:template>

    <xsl:template name="addRecord">
    <xslaram name="source"><xsl:value-of select="source"/></xslaram>
    <xslaram name="columns"><xsl:value-of select="columns"/></xslaram>
    <xslaram name="row"><xsl:value-of select="record"/></xslaram>
    <xsl:call-template name="addColumn">
    <xsl:with-param name="source"><xsl:value-of select="$source"/></xsl:with-param>
    <xsl:with-param name="columns"><xsl:value-of select="$columns"/></xsl:with-param>
    <xsl:with-param name="row"><xsl:value-of select="$row"/></xsl:with-param>
    <xsl:with-param name="column">1</xsl:with-param>
    </xsl:call-template>
    </xsl:template>

    <xsl:template name="addColumn">
    <xslaram name="source"><xsl:value-of select="source"/></xslaram>
    <xslaram name="columns"><xsl:value-of select="columns"/></xslaram>
    <xslaram name="row"><xsl:value-of select="row"/></xslaram>
    <xslaram name="column"><xsl:value-of select="column"/></xslaram>
    <xsl:choose>
    <xsl:when test="number($column) > number($columns)">
    <xsl:if test="$source != ''">
    <xsl:call-template name="addRecord">
    <xsl:with-param name="source"><xsl:value-of select="$source"/></xsl:with-param>
    <xsl:with-param name="columns"><xsl:value-of select="$columns"/></xsl:with-param>
    <xsl:with-param name="row"><xsl:value-of select="$row + 1"/></xsl:with-param>
    </xsl:call-template>
    </xsl:if>
    </xsl:when>
    <xsltherwise>
    <cell>
    <xsl:attribute name="row"><xsl:value-of select="$row"/></xsl:attribute>
    <xsl:attribute name="column"><xsl:value-of select="$column"/></xsl:attribute>
    <xsl:choose>
    <xsl:when test="contains($source, ';')">
    <xsl:value-of select="substring-before($source, ';')"/>
    </xsl:when>
    <xsltherwise>
    <xsl:value-of select="$source"/>
    </xsltherwise>
    </xsl:choose>
    </cell>
    <xsl:call-template name="addColumn">
    <xsl:with-param name="source"><xsl:value-of select="substring-after($source,
    ';')"/></xsl:with-param>
    <xsl:with-param name="columns"><xsl:value-of select="$columns"/></xsl:with-param>
    <xsl:with-param name="row"><xsl:value-of select="$row"/></xsl:with-param>
    <xsl:with-param name="column"><xsl:value-of select="$column + 1"/></xsl:with-param>
    </xsl:call-template>
    </xsltherwise>
    </xsl:choose>
    </xsl:template>

    </xsl:stylesheet>


    Jason Sobell iGadget <igadget_@hotmail.com> wrote:
    >It's possible, but very very messy, and not what XSLT is designed to do.
    >Look at the various string functions such as:
    >substring
    >substring-after
    >substring-before
    >string-length
    >translate
    >substring
    >
    >It would be a nightmare to implement though, so you are far better to
    >preparse the data and convert these strings into tags and/or attributes.
    >You are not performing XML transformation here, you are performing data


    >transformation.
    >
    >Cheers,
    > Jason
    >
    >On 7 Feb 2003 07:50:54 -0800, Davide wrote:
    >
    >>
    >> Hello,
    >> this problem is driven me crazy.
    >> I do have a sort of xml, and I need to transform it in another one.
    >> It is not a problem, but the structure of this one is not so clear.
    >> It is a table (2 col, 3 rows), but all records are in sequence with an

    ";"
    >> as separator. Is there any kind of function in xslt to manage this format...Thanks,
    >> in advance,
    >> davide
    >>
    >>
    >>
    >> <IFVariable name="WorkingTable" flags="4259841" version="1.3.39.0" type="table">{8;8}[2;3]111111;BL;222222;BL;333333;MM
    >>
    >>
    >> <IFMethod name="AddDispatchMethods" flags="66048" type="IFNativeMethod"/><IFComponent
    >> name="ColumnDescription" flags="65537" type="IFComponent"><IFVariable

    name="Column001"
    >> flags="65536" type="string"/><IFVariable name="Column002" flags="65536"

    type="string"/></IFComponent></IFVariable>


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center