Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

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>
[857 byte] By [Davide] at [2007-11-9 15:28:04]
# 1 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>
Jason Sobell iGadget at 2007-11-11 23:29:46 >
# 2 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">
<xsl:output 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">
<xsl:param name="curNode"><xsl:value-of select="curNode"/></xsl:param>
<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">
<xsl:param name="source"><xsl:value-of select="source"/></xsl:param>
<xsl:param name="columns"><xsl:value-of select="columns"/></xsl:param>
<xsl:param name="row"><xsl:value-of select="record"/></xsl:param>
<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">
<xsl:param name="source"><xsl:value-of select="source"/></xsl:param>
<xsl:param name="columns"><xsl:value-of select="columns"/></xsl:param>
<xsl:param name="row"><xsl:value-of select="row"/></xsl:param>
<xsl:param name="column"><xsl:value-of select="column"/></xsl:param>
<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>
<xsl:otherwise>
<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>
<xsl:otherwise>
<xsl:value-of select="$source"/>
</xsl:otherwise>
</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>
</xsl:otherwise>
</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>
Tom Larson Jayhill Software Inc at 2007-11-11 23:30:42 >