Index matching on the basis of occurence in a xml

Hi All,

I read some of your articles, they are really fascinating. I am bugged with a problem of xml transformation using XSL. I tried at lots of places but i am not able to garner much help. I think you will be able to provide me with some thoughts/solution to this.

My problem is as follows.

I have this xml,

<table>

<head>

<row>

<cr colspan="1" rowspan="3"/>

<hg-hg colspan="6" rowspan="1" >

<caption caption="Ev"/>

</hg-hg>

</row>

<row>

<c-hg colspan="2" rowspan="1">

<caption caption="Manufacturing"/>

</c-hg>

<c-hg colspan="1" rowspan="1">

<caption caption="IT"/>

</c-hg>

<c-hg colspan="3" rowspan="1">

<caption caption="Inventory"/>

</c-hg>

</row>

<row>

<hg-hg colspan="1" rowspan="1">

<caption caption="Product"/>

</hg-hg>

<c-hg colspan="1" rowspan="1">

<caption caption="Units"/>

</c-hg>

<c-hg colspan="1" rowspan="1">

<caption caption="$ Amount"/>

</c-hg>

<c-hg colspan="1" rowspan="1">

<caption caption="Units"/>

</c-hg>

<c-hg colspan="1" rowspan="1">

<caption caption="Units"/>

</c-hg>

<c-hg colspan="1" rowspan="1">

<caption caption="Cost"/>

</c-hg>

<c-hg colspan="1" rowspan="1">

<caption caption="$ Amount"/>

</c-hg>

</row>

</head>

<body>

<row>

<r-hg colspan="1" indent="1" rowspan="1">

<caption caption="AAA"/>

</r-hg>

<l value="500"/>

<l value="62,823,395"/>

<l value="441"/>

<l value="123"/>

<l value="635,600"/>

<l value="49,600"/>

</row>

<row>

<r-hg colspan="1" indent="1" rowspan="1" style="odd">

<caption caption="BBB"/>

</r-hg>

<l value="921"/>

<l value="283,835,573"/>

<l value="879"/>

<l value="13"/>

<l value="65,300"/>

<l value="65,600"/>

</row>

<row>

<r-hg colspan="1" indent="1" rowspan="1">

<caption caption="CCC"/>

</r-hg>

<l value="487"/>

<l value="64,593,105"/>

<l value="487"/>

<l value="23"/>

<l value="756,600"/>

<l value="121,600"/>

</row>

</body>

</table>

The xml as three parts, dept row (manufacturing, it, inventory), the category of there displayed (units, cost, amount) and the third is the data. Here the index are matched, like the units for manufacturing will be AAA-500, BBB-921, CCC-487. Similarly for IT we don't have units. The out from this xml is determined by the inputs (means param or some part appended to the dom). Like if the input is to get the units for all the products for Manufacturing or Inventory. I am not able to figure out a way for this.

Hope you can help me on this.

Thanks, any help from you will be greatly appreciated.

Regards

Kunal

[3409 byte] By [kunaljain18na] at [2007-11-27 7:56:42]
# 1
> I tried at lots of places but i am not able to garner much help.That's because you haven't done anything yet. Nobody wants to write your XSL for you. On the other hand if you posted something that you had done, even if it didn't work, we could use that as a starting point.
DrClapa at 2007-7-12 19:38:20 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 2

Hi,

Its not that case, I have written one xsl which was working for one case but not for a very generic case. The inputs i am taking about i have appeneded them in the document which are given to the transform api, or for proof of concept i am setting it as a param. I have written the following xsl..

<?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" indent="yes"/>

<xsl:param name="value" />

<xsl:variable name="c-hg" />

<xsl:template match="/table">

<output>

<delivery>

<xsl:apply-templates select="body/row/r-hg"/>

</delivery>

<xsl:for-each select="head/row[2]/c-hg" >

<xsl:variable name="c-hg" >

<xsl:value-of select="caption/@caption" />

</xsl:variable>

<xsl:variable name="tempIndex"> <!-- Find index of main header, eg Manufacturing -->

<xsl:for-each select="/table/head/row[2]/c-hg">

<xsl:if test="$c-hg = caption/@caption" >

<xsl:value-of select="position()"/>

</xsl:if>

</xsl:for-each>

</xsl:variable>

<xsl:variable name="dcolspan" >

<xsl:for-each select="/table/head/row[2]/c-hg[1]" >

<xsl:value-of select="@colspan" />

</xsl:for-each>

</xsl:variable>

<xsl:variable name="tempIndex2" select="count((/mdxtable/head/row[3]/c-hg[caption/@caption = $value])[1]/preceding-sibling::*) " />

<xsl:variable name="index">

<xsl:value-of select="$tempIndex2 + ($tempIndex - 1) * $dcolspan"/>

</xsl:variable>

<dataset seriesName="{$c-hg}">

<xsl:apply-templates select="/table/body/row/l[position() = $index]"/>

</dataset>

</xsl:for-each>

</output>

</xsl:template>

<xsl:template match="l">

<set value="{@value}"/>

</xsl:template>

<xsl:template match="r-hg">

<del label="{caption/@caption}"/>

</xsl:template>

</xsl:stylesheet>

This i tried to get the following output xml

<output >

<delivery>

<del label="AAA"/>

<del label="BBB"/>

<del label="CCC"/>

</delivery>

<data seriesName="Manufacturing">

<set value="500"/>

<set value="921"/>

<set value="487"/>

</data>

<data seriesName="IT">

<set value="441"/>

<set value="879"/>

<set value="487"/>

</data>

</output>

The case here is that, if the input xml for a scenario has only manufacturing and it and the colspan for both is 2 and both have units and amount in the second row then this works. But if the layout of the input xml changes this one doesnt work. I tried to have some global params whose values i can retain through the for-each loop but that didnt worked, i also tried having expr attribute with param, but my transform api gave the exception that expr is not allowed with param, in some cases i got the exception that params are not allowed.

I have been working with this kind of approches, please have a look and suggest me how to move fwd.

Thanks a lot.

Regards

Kunal

kunaljain18na at 2007-7-12 19:38:20 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 3

Seems like the problem is you don't understand how the input XML is structured. Or if you do, you can't explain it. (And if you can't explain it then naturally you can't write programs that depend on your understanding it.)

Let's take an example of what you said:

"Here the index are matched, like the units for manufacturing will be AAA-500, BBB-921, CCC-487. Similarly for IT we don't have units."

Why does Manufacturing get those values? Why doesn't IT get any values?

DrClapa at 2007-7-12 19:38:20 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 4

Hi,

The input XML is based on result of some db queries which uses joins to fetch certain data, this comes from a different component. Now my task is to parse this xml and get the result out. In some cases the joins result are different but will be governed by the colspan for the depts. Like manufacturing have a colspan of 2, IT 1, and inventory 3. So in the second row, baring the first column, the first 2 (units and amount) belong to manufacturing, 3rd (Units) belong to IT and 4th, 5th 6th (Units, cost and Amount) belongs to inventory. This gives the order in which the values will be there in the body of the xml. No i have to take out certain things out of this xml, like to show how much is the individual amount is there for all or how much are the individual units for all three, These are the permutatin combination in which i require the result.

It is not having that value is because the joins doesnt yields that or its not of use. So if some dept doesnt have any value, that dept has to be ignored.

The main problem which i am facing here is to have certain global variable/param whose values are retained through the for-each loops, and making certain flags which check whether the certain value (unit, amount, cost) existed for the depts or not. I am not able to get this done.

Thanks

Kunal

kunaljain18na at 2007-7-12 19:38:20 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...