xsl-list
[Top] [All Lists]

Re: identity transformation problem

2003-03-13 13:51:35
At 2003-03-13 11:54 -0800, Mac Martine wrote:
 I am basically doing an identity transformation (copying xml tree), but
adding attributes in certain places.

An XSLT stylesheet is obliged to produce the result tree in result parse order, so for the bulk of your transform, the copying of the source XML tree to the result tree is straightforward.

I need to change the value of an attribute in my 'testSuite' element to
one value if I add a @task attribute to any element. If I don't add an
@task attribute to any elements then I want to update that attribute in
the 'testSuite' element to a different value. This 'testSuite' element
is always a child of the root element. I can't figure out how to do
this...

You are using the terms "change" and "update" ... but you cannot do that to the result tree. Once created, nodes in the result tree cannot be changed. The processor isn't even obliged to keep it around in memory and can serialize it instantly to a result file if you are asking the processor to produce syntax for your result.

Your obligation is not to "change" or "update" the result tree, but to put out the result tree as desired *the first time around*. This requires you to do all of your logic for the value of the testSuite attribute *at the time the testSuite attribute is added to the result tree*, which will be long before you actually get around to putting out the individual attributes deep inside the tree.

This isn't as difficult as it may sound ... at the time you are doing the testSuite child of the document element, at the time you need to add the currentTask attribute, do whatever checking you need to do through the entire source node tree to establish the value of @currentTask. Then continue producing the result tree doing whatever you need to do with the individual constructs, knowing that when you did the testSuite element you already set its attribute value as desired.

I hope this helps.

.............. Ken

--
Upcoming hands-on in-depth XSLT/XPath and/or XSL-FO
                             North America:      June 16-20, 2003

G. Ken Holman                mailto:gkholman(_at_)CraneSoftwrights(_dot_)com
Crane Softwrights Ltd.         http://www.CraneSoftwrights.com/s/
Box 266, Kars, Ontario CANADA K0A-2E0   +1(613)489-0999 (F:-0995)
ISBN 0-13-065196-6                      Definitive XSLT and XPath
ISBN 0-13-140374-5                              Definitive XSL-FO
ISBN 1-894049-08-X  Practical Transformation Using XSLT and XPath
ISBN 1-894049-10-1              Practical Formatting Using XSL-FO
Male Breast Cancer Awareness http://www.CraneSoftwrights.com/s/bc


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