Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 7th, 2007, 05:28 PM
Registered User
 
Join Date: Aug 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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.





Similar Threads
Thread Thread Starter Forum Replies Last Post
accessing elements using document() function geoGregory3 XSLT 2 February 28th, 2008 07:39 PM
Problem comparing xml data vb6 method Pro VB 6 5 May 9th, 2007 11:19 AM
Get all elements from XML olster XSLT 0 February 13th, 2007 06:39 AM
convert elements based on place in document jefke XSLT 2 May 17th, 2004 05:32 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.