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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

comparing 2 XML files

Status
Not open for further replies.

xmlrules

Programmer
Jul 9, 2002
1
0
0
GB
Ok, what I`m trying to do is name an actor and a character id (cid) in one file (611.xml) and use the XSLT to compare it to another file (authors.xml) where the actor's name will be found and the cid compared to a cid contained within the 'actor' tag. The name of the character and url of a page for that character will then be output.

I've managed to get the majority of this to work except for when it finds matching results, it repeats them twice. Therefore if it finds the following in the authors.xml file which match the details in 611.xml:

Colin Cunningham - Maj. Paul Davis
John DeLancie - Col. Simmons
Claudia Black - Aeryn Sun

then it will output the following:

Colin Cunningham - Maj. Paul Davis
John DeLancie - Col. Simmons
Claudia Black - Aeryn Sun
Colin Cunningham - Maj. Paul Davis
John DeLancie - Col. Simmons
Claudia Black - Aeryn Sun

I believe that as the 'cid' tags all equal 1 (as in character No. 1 for that actor) then it is matching each 'cid' with each character.

So when it finds Colin Cunningham in the authors.xml file, it matches the 'cid' not only with the 'cid' contained within that 'actor' tag, but also with the 'cid' tags contained within the 'actor' tags belonging to John DeLancie and Claudia Black.

Does anyone know of a way to match the actor name *only* with a 'cid' tag contained within that 'actor' tag.

Just incase this doesn't make any sense, below are the files I am using.

**611.xml**
<?xml version=&quot;1.0&quot;?>
<EPISODE TITLE=&quot;Prometheus&quot; EPNO=&quot;611&quot; RATING=&quot;n/a&quot;
xmlns:ref=&quot; ref:noNamespaceSchemaLocation=&quot;xsd_PostingML.xsd&quot;
xmlns:pml=&quot; pml:noNamespaceSchemaLocation=&quot;xsd_PostingML.xsd&quot;>
<GCAST>

<GUEST>
<PERFORMER NAME=&quot;Colin Cunningham&quot; CID=&quot;1&quot;/>
</GUEST>

<GUEST>
<PERFORMER NAME=&quot;John DeLancie&quot; CID=&quot;1&quot;/>
</GUEST>

<GUEST>
<PERFORMER NAME=&quot;Bill Marchant&quot; CID=&quot;1&quot;/>
</GUEST>

</GCAST>
</EPISODE>



**pstyle_episodes.xsl (code that does the matching)**

<xsl:for-each select=&quot;GCAST/GUEST&quot;>

<xsl:if test=&quot;count(PERFORMER) = 1&quot;>
<xsl:choose>
<xsl:when test=&quot;count(PERFORMER/@CID) = 1&quot;>

<xsl:if test=&quot;$biogs/actor/@name = PERFORMER/@NAME and $biogs/actor/character/@cid = PERFORMER/@CID&quot;>
<xsl:for-each select=&quot;$biogs/actor&quot;>
<xsl:value-of select=&quot;@name&quot;/> -
<a href=&quot;{character/url}&quot;>
<xsl:value-of select=&quot;character/name&quot;/>
</a><br/>
</xsl:for-each>
</xsl:if>

</xsl:when>
<xsl:eek:therwise>
<xsl:value-of select=&quot;PERFORMER/@NAME&quot;/> -
<xsl:value-of select=&quot;CHARACTER/ROLE/@NAME&quot;/><br/>
</xsl:eek:therwise>
</xsl:choose>
</xsl:if>

</xsl:for-each>


**authors.xml**
<root>

<actor name=&quot;Colin Cunningham&quot;>
<character cid=&quot;1&quot;>
<name>Maj. Paul Davis</name>
<url>personnel.asp?race=tauri&amp;pers=pauldavis</url>
</character>
</actor>

<actor name=&quot;John DeLancie&quot;>
<character cid=&quot;1&quot;>
<name>Col. Simmons</name>
<url>personnel.asp?race=tauri&amp;pers=simmons</url>
</character>
</actor>

<actor name=&quot;Claudia Black&quot;>
<character cid=&quot;1&quot;>
<name>Aeryn Sun</name>
<url>personnel.asp?race=sebacean&amp;pers=aerynsun</url>
</character>
</actor>

</root>
 
I don't know if this is your problem, but in the first 'when' element:

<xsl:when test=&quot;count(PERFORMER/@CID) = 1&quot;>

This is true when the number of PERFORMER element that have a CID attribute is equal to 1. I don't think this is what you're after here.

As to your problem - This is what your XSL does:
For every GUEST in GCAST that has exactly 1 PERFORMER, if PERFORMER/@NAME matches $biogs/actor/character/@name and PERFORMER/@CID matches $biogs/actor/character/@cid then for every actor in $biogs print the name and a link to the first character/url under actor as character/name followed by a break - otherwise print PERFORMER/@NAME and something you don't list above...

I don't think you want to write the entire list of every actor element under $biogs for each GUEST that matches. You need a tighter select in the second for-each. I'd try to give you one, but I don't have enough of the XML to know eactly what you were after. You'll probably have to capture the name and cid in variables and match them, like in &quot;$biogs/actor[character/name=$name and character/@cid=$cid]&quot;

Sorry, that may be more confusing than helpful.

Uura
~~~~
&quot;Common sense tells you that the world is flat.&quot;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top