RE: [xsl] Problem with getting values from two files

Subject: RE: [xsl] Problem with getting values from two files
From: Jarno.Elovirta@xxxxxxxxx
Date: Fri, 3 May 2002 09:27:38 +0300

> Is is possible by XSLT
> File A.
> <Name value="Johan"/>
> <Address Value="JohanCompositAddress" Type="CompositeAddress"/>

document() function can only be used to retrieve well-formed XML documents and your File A is not well-formed. If you add a wrapper element, either by changing the file or using a wrapper XML document where you include the File A using external general entity, then it will work.

> File B.
> <CompositeAddress>
> <JohanCompositeAddress>
> <Address Value ="NewYork"/>
> <Address Value ="Paris"/>
> </JohanCompositeAddress>
> </CompositeAddress>
> Resultant File.
> <UserName Value="Johan"/>
> <UserAddres>
> <Address Value="NewYork"/>
> <Address Value="Paris"/>
> </UserAddres>
> Here I want to get the result by the Single XSL file...What 
> I'm supposing
> ..the required XSL should do is
> 1. Check the type attribute of Address node of File A.
> 2. If it is CompositeAddress..then it should take the value (ie
> JohanCompositAddress) attribute of the address node of File A 
> and check it
> ...whether it is present in File B. "JohanCompositAddress"
> 3. And if it is present in file B then fetch out all the 
> address against
> <JohanCompositeAddres> and show it in the resultant file.

If you wrap the File A into some element and fix files so that the "JohanCompositeAddress" string is the same in both files, then e.g.

  <xsl:variable name="value" select="document('File A.')//Address[@Type = 'CompositeAddress']" />
  <xsl:for-each select="document('File B.')/CompositeAddress/*[name() = $value/@Value]">
    <UserName Value="{$value/preceding-sibling::Name[1]/@value}"/>
      <xsl:copy-of select="Address" />

The node $value is bound to and the node-set the xsl:for-each selects might not be the best possible, change them to better suit the whole structure of your source document. Also, the next time you ask a question on the list, it might be worth it posting your non-functioning XSLT stylesheet and ask how to fix it, instead of asking for a whole solution.



 XSL-List info and archive:

Current Thread