Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Evaluating XML Fields to Find Other XML Data

Status
Not open for further replies.

HIGHI

Programmer
Oct 10, 2001
2
US
My current project merges XML data from different sources and performs server-side processing with XSL stylesheets. Here's what I'm trying to accomplish:

Data Source 1 (example)
<flag1>
true
</flag1>
<flag2>
false
</flag2>

Obviously flag1 and flag2 would be unique entities in the above data. In my case, they're coming from a database.

Data Source 2 (example)
<displayMe btnName=&quot;Button1.gif&quot; useFlag=&quot;flag1&quot;>
<displayMe btnName=&quot;Button2.gif&quot; useFlag=&quot;flag2&quot;>

I want to evaluate the CONTENTS of the field listed in useFlag, effectively getting the value-within-a-value. Or stated another way, how do I get the value 'true' by only referencing useFlag (I don't want to code all of the possible flag names into the XSL sheet.)

So what I don't want, is

<xsl:if test=&quot;@useFlag='flag1' and flag1='true'&quot;>
blah blah
</xsl:if>

because the flags are dynamic and numerous.

Any suggustions?

Thanks!

Brian :cool:
 
if you are putting the datasource2 xml into the stylesheet you could reference datasource1 from the xsl.

if you changed the datasource1 xml to a structure more like

<flag id=&quot;1&quot;>true</flag>
<flag id=&quot;2&quot;>false</flag>

and make source2
<displayMe btnName=&quot;Button1.gif&quot; useFlag=&quot;1&quot;>

then
<xsl:for-each select=&quot;displayMe&quot;>
<xsl:variable name=&quot;flagid&quot; select=&quot;@useFlag&quot;/>
<xsl:value-of select=&quot;document('datasource2.xml')/flag[@id=$flagid]&quot;/>
</xsl:for-each>

HTH
 
MrTom,

Thanks for the speedy reply. However I'm not sure this will help me. The XML data is truly being 'merged' prior to introduction to the stylesheet, so there is only one document.

Your second point, of reassigning all of the flags in the database to be flag elements with an id attribute set to the database field name is possibly a help, but then data coming from the database would have to be processed in multiple fashions, depending upon the type of data (flag versus other). I'm hoping to avoid this if I can.

Thanks again!

Brian ;-)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top