Click to See Complete Forum and Search --> : use variables in xsl ?


tyris
July 11th, 2001, 11:03 AM
hi all,
i do have an xml document this way :


<document name="Marketing">
<tables count="1">
<table name="AllDocuments">
<columnHeaders count="3">
<columnHeader text="Site"/>
<columnHeader text="Status"/>
<columnHeader text="Account"/>
</columnHeaders>
<rows count="134">
<row>
<column>Paris</column>
<column>Project Completed</column>
<column>Microsoft (France)</column>
</row>
<row>
<column>Paris</column>
<column>Project Completed</column>
<column>Lionbridge Nortel</column>

</row>
</rows>
</table>
</tables>
</document>


what i'd like is :
display each row "talking" about the Account. i thought i could make a </xsl:if test="columnHeaders='Account'"> then give the number of the row (incremented at each columnHeaders i found)
and then for each <column> use a second variable incremented, test if this one is equal to the one for columnHeaders and if yes, display it.

i don't know how it could be done. is there a way :
1. to use variable and increment them
2. test them with and other variable
Best regards ,
Elise


regards ;-)

elise

dressegu
July 12th, 2001, 04:42 PM
Is it possible to redesign your XML document? I usually try to design it so that order doesn't matter. For example, if you were to read in your XML using DOM, I don't think you are guaranteed that it will be recreated in the same order. I would suggest rewritting the XML to look something more like:


<document name="Marketing">
<table name="AllDocuments">
<row>
<Site>Paris</Site>
<Status>Project Completed</Status>
<Account>Microsoft (France)</Account>
</row>
</table>
</document>

Here you can still get all the counts you had before using XSL. Example:

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

Similarly you could get row counts.

To get the column headers, you could just get the name of each tag under the first row or something. And now when you want to list all the accounts, you don't have to do any counting, you just look for that tag directly.

At a quick glance I don't think you lose any information by restructuring it as I described above. I guess alternately you could use an attribute for each of the column and columnHeader tags, maybe num="1", num="2", etc. Then you could search for the columnHeader tag with text="Account" and get its number, then find all matching row/column tags. I think one of these two solutions would be preferred to having to make convoluted counter variables. Where there other reasons you have the XML structured the way it is?

David

tyris
July 13th, 2001, 03:49 AM
i can't because
1. sometimes there is no value for the columnHeader
2. that would make too much redundance no ?

in fact i create this xml file after retrieving results for a query submited to a Notes DB view, where sometimes column names are not entered.

this xml is done by a buddy, i could maybe ask to make some small changes. i have also thought of an trribute like you said (a kind of ID).
for the moment i try to do without any change of the xml file. the only problem is the variable scope (see the other post i putted)
sorry for my bad english.


regards ;-)

elise

tyris
July 13th, 2001, 04:19 AM
"Then you could search for the columnHeader tag with text="Account" and get its number, then find all matching row/column tags. "

do you have an example with a match row/column tag with the sale id ? i mean what kind of code would it be ?



regards ;-)

elise

tyris
July 13th, 2001, 07:26 AM
that's okay, we finnaly completly change the DTD and the xml composition, that will now be done without pain :)

regards ;-)

elise