Hi John,
For each of the <Field Code="DESC"> node, i need to generate an result node
to store all text values under <Value> node.
Sample source xml:
<fields>
<Field Code="DESC">
<List>
<Value lang="fr" Code="DESC">
<B>00 ab</B>
<DI/>
<S>t</S>
<SP/>– <S>ƒ</S>145/200<DI/>CHF<SP/>
<S>„</S>195/300<DI/>CHF</Value>
</List>
</Field>
<Field Code="DESC">
<List>
<Value lang="en" Code="DESC">
<B>25 rm</B>
<DI/>
<S>t</S>
<SP/>– <S>ƒ</S>145/200<DI/>CHF<SP/>
<S>„</S>195/300<DI/>CHF</Value>
</List>
</Field>
</fields>
Expected output:
<results>
for $nodes in $data//fields/Field[Code="DESC"]
return
<result>{$nodes/string()}</result> (:This would join all the node values
under DESC and then return the result :)
</results>
Here I need to apply condition only for <S> nodes. whenever it is node <S>,
instead of the value t/ƒ/„ i need to output the value as 1/2/3
If the result is something like
00 abt– ƒ145/200CHF„195/300CHF
I need it as
00 ab1– 2145/200CHF3195/300CHF (:t/ƒ/„ values changed to 1/2/3
respectively:)
How do I do this?
Thanks
On Wed, Sep 4, 2013 at 7:19 PM, John Zhong <[email protected]> wrote:
> for $field in $doc//field
> return <output>{fn:string-join(($field/(A,B), if($field/C eq 'z') then
> '012' else if($field/C eq 'x') then '098' else $field/C))}</output>
>
> John
>
>
> On Wed, Sep 4, 2013 at 9:33 AM, sini narayanan <[email protected]>wrote:
>
>> Hi All,
>>
>> I have an xml file with the following structure
>> <fields>
>> <field>
>> <A>abc</A>
>> <B>def</B>
>> <C>z</C>
>> </field>
>> <field>
>> <A>abc</A>
>> <B>def</B>
>> <C>x</C>
>> </field>
>> </fields>
>>
>> For each of the field nodes, I need to generate the output as the node
>> value of all the child nodes under a field node.
>> ie: <output>abcdefz</output>
>> <output>abcdefx</output>
>>
>> This I can simply get it using the string() value.
>>
>> let $doc := doc("/Test/file.xml")
>> for $i in $doc//fields/field
>> return
>> <output>{$i/string()}</output>
>>
>> But here I need an extra processing to be done only for node <C>. ie.
>> based on the node value of C node, i need to perform a translation.
>> If C/text() eq z then 012 should be the output and if C/text() eq x then
>> 098 should be the output.
>>
>> So the final output expected is
>> <output>abcdef012</output>
>> <output>abcdef098</output>
>>
>> How do I achieve this easily in the code that I mentioned earlier.
>>
>> Thanks,
>> Sini
>>
>> _______________________________________________
>> General mailing list
>> [email protected]
>> http://developer.marklogic.com/mailman/listinfo/general
>>
>>
>
> _______________________________________________
> General mailing list
> [email protected]
> http://developer.marklogic.com/mailman/listinfo/general
>
>
_______________________________________________
General mailing list
[email protected]
http://developer.marklogic.com/mailman/listinfo/general