Hi Can anyone help me make the following selection? For element which has a tag3 value "fr" choose tag4 value concatenated with the value of tag4 value for the element whose tag3 is "nl" If tag4 is missing (for "fr" or "nl") then choose tag5 value For the following example, I need the output to be 3 2 Thanks Mahmoud <tag1> <tag2> <tag3>nl</tag3> <tag5>2</tag5> </tag2> <tag2> <tag3>fr</tag3> <tag4>3</tag4> <tag5>4</tag5> </tag2> <tag2> <tag3>en</tag3> <tag4>5</tag4> <tag5>6</tag5> </tag2> </tag1>
khalil_mi@hotmail.com wrote: > Can anyone help me make the following selection? > For element which has a tag3 value "fr" choose tag4 value concatenated > with the value of tag4 value for the element whose tag3 is "nl" > > If tag4 is missing (for "fr" or "nl") then choose tag5 value What kind of solution are you looking for? Here is an XQuery solution: let $doc := doc('input.xml') let $fr := $doc/tag1/tag2[tag3 = 'fr'] let $nl := $doc/tag1/tag2[tag3 = 'nl'] return concat(($fr/tag4, $fr/tag5)[1], ' ', ($nl/tag4, $nl/tag5)[1]) You can use XQuery with Saxon 9 from <URL:http://saxon.sourceforge.net/> or with Altova XML tools from <URL:http://www.altova.com/altovaxml.html> -- Martin Honnen --- MVP XML http://JavaScript.FAQTs.com/
On Feb 6, 2:30 pm, Martin Honnen wrote: > khalil...@hotmail.com wrote: > > Can anyone help me make the following selection? > > For element which has a tag3 value "fr" choose tag4 value concatenated > > with the value of tag4 value for the element whose tag3 is "nl" > > > If tag4 is missing (for "fr" or "nl") then choose tag5 value > > What kind of solution are you looking for? > > Here is an XQuery solution: > > let $doc := doc('input.xml') > let $fr := $doc/tag1/tag2[tag3 = 'fr'] > let $nl := $doc/tag1/tag2[tag3 = 'nl'] > return concat(($fr/tag4, $fr/tag5)[1], ' ', ($nl/tag4, $nl/tag5)[1]) > > You can use XQuery with Saxon 9 from <URL:http://saxon.sourceforge.net/> > or with Altova XML tools from <URL:http://www.altova.com/altovaxml.html> > -- > > Martin Honnen --- MVP XML > http://JavaScript.FAQTs.com/ thanks Martin I forgot to specify that i need an XSL solution Mahmoud
khalil_mi@hotmail.com wrote: > I forgot to specify that i need an XSL solution Here is an XSLT 1.0 stylesheet <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:output method="text"/> <xsl:template match="tag1"> <xsl:variable name="fr" select="tag2[tag3 = 'fr']"/> <xsl:variable name="nl" select="tag2[tag3 = 'nl']"/> <xsl:value-of select="concat( $fr[tag4]/tag4 | $fr[not(tag4)]/tag5, ' ', $nl[tag4]/tag4 | $nl[not(tag4)]/tag5 )"/> </xsl:template> </xsl:stylesheet> -- Martin Honnen --- MVP XML http://JavaScript.FAQTs.com/