Comparing elements in an XML document
I am trying to compare the element names in an XSL document and am having problems getting it done. By the way, I am using XSLT to process the XML document. Here is my situation:
Sample XML:
<dfd>
<field num="1">
<sub>1</sub>
<heading />
<descr>Description 1-1</descr>
<tag>tag-1-1</tag>
</field>
<field num="2">
<sub>1</sub>
<heading>This is my heading 2-1</heading>
<descr />
<tag />
</field>
<field num="2">
<sub>2</sub>
<heading />
<descr>Description2-2</descr>
<tag>tag-2-2</tag>
</field>
<dfd>
<dfes>
<dfe-tag-1-1>Description 1-1</dfe-tag-1-1>
<dfe-tag-1-2>Description 2-2</dfe-tag-1-2>
<dfe-tag-2-1>Description 2-1</dfe-tag-2-1>
<dfe-tag-2-2>Description 2-2</dfe-tag-2-2>
<dfe-tag-2-3 />
<dfe-tag-2-4/>
</dfes>
What I need to do is to loop through all of the dfd/field elements that have the same num attribute one at at time and loop through the dfes elements looking for a dfe element with the same name as the dfd/tag with dfe- concatenated on the front of it. If I find the matching element in the dfes elements then I need to ensure there is a text value associated with that element and return either the text value of the element or a boolean true that it was found.
Example:
Loop dfd/fields[@num = 2]
set variable dfdele to concat('dfe-', tag)
loop dfes/* elements
if dfes/child[name] contains the value in dfdele
set a variable value to either the text value of the dfe/child
or set a boolean to true so that when this loop is finished
there is a value advising me that the element was found in
the dfes tree
end-if
end-loop
end-loop
Synopsis - what I need to know is if there is a field element with the same attribute number as the attribute number I am processing and it has a tag value, is there a matching element in the dfes tree that contains the tag value with a dfe- concatenated on the front.
Any help would be muchly appreciated.
|