Ureader.com  
Microsoft software help and Community
   home   |   control panel login   |   archive   |  
 
XML
data.xmlanalysis
mappoint.webservice
msf
msxml-webrelease
netmyservices.sdk
passport.sdk
soap
soapsdk
uddi.general
uddi.programming
uddi.specification
xml
xmlsqlwebrelease
xsl
  
 
date: Wed, 6 Feb 2008 05:06:58 -0800 (PST),    group: microsoft.public.xsl        back       


complex selection   
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>
date: Wed, 6 Feb 2008 05:06:58 -0800 (PST)   author:   unknown

Re: complex selection   
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/
date: Wed, 06 Feb 2008 14:30:58 +0100   author:   Martin Honnen

Re: complex selection   
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
date: Wed, 6 Feb 2008 05:35:21 -0800 (PST)   author:   unknown

Re: complex selection   
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/
date: Wed, 06 Feb 2008 15:08:21 +0100   author:   Martin Honnen

Google
 
Web ureader.com


    COPYRIGHT 2007, YARDI TECHNOLOGY LIMITED, ALL RIGHT RESERVE  |   contact us