Project

Profile

Help

XSLT with 2 XML input-variables

Added by Anonymous over 16 years ago

Legacy ID: #5163465 Legacy Poster: vertig (vertig)

Hi all, Please find below a concrete issue regarding an XSL Transformation. Please do NOT hesitate to sent your ideas / feedbacks / comments and ...hopefully solutions. Many thanks, Regards, Nicolas Guerin I have actually two XML input-variables: the first variable is a list of friends (ID / Name) and the second variable is a list of IDs. I would like to use a XslT to get as output-variable a list of friends with only the friends whose ID are included in the list of IDs (2nd variable) Does anybody knows how to write the corresponding xslt ? First input-variable: <friendList> <name> <ID>1</ID> <Name>Nico</Name> </friend> <friend> <ID>2</ID> <Name>Bob</Name> </friend> <friend> <ID>3</ID> <Name>John</Name> </friend> <friend> <ID>4</ID> <Name>Mike</Name> </friend> </friendList> 2nd input-variable: <IDList> <ID>1</ID> <ID>3</ID> </IDList> Requested output-variable (after transformation): <friendList> <name> <ID>1</ID> <Name>Nico</Name> </friend> <friend> <ID>3</ID> <Name>John</Name> </friend> </friendList>


Replies (1)

RE: XSLT with 2 XML input-variables - Added by Anonymous over 16 years ago

Legacy ID: #5163531 Legacy Poster: Willem van Heerde (wheerde)

Hi Nicolas, Try something like this $var1 is the friendlist and $var2 the id-list): <friendList> <xsl:for-each select="$var2/idlist/id"> <xsl:copy-of select="$var1/friendlist/friend[id = current()] "/> </xsl:for-each> </friendList> Or even shorter: <friendList> <xsl:copy-of select="$var1/friendlist/friend[id = $var2/idlist/id] "/> </friendList> I did not test it but I think this should work. Willem.

    (1-1/1)

    Please register to reply