The following XML sample shows data records of type 'Master', which are linked to 0..N contents of type 'Series'. I want to detect the number of existing Series records for Masters with the same title () attribute.
<?xml version="1.0" encoding="UTF-8"?>
<program_file fechaCreacion="20180919184224">
<version>1.0</version>
<programs>
<program id_programa="1">
<tipo_programa>Master</tipo_programa>
<titulo >tit1</titulo>
<año>2018</año>
</program>
<program id_programa="2">
<tipo_programa>Master</tipo_programa>
<titulo >tit1</titulo>
<año>2018</año>
</program>
<program id_programa="3">
<tipo_programa>Master</tipo_programa>
<titulo >tit2</titulo>
<año>2018</año>
</program>
<program id_programa="5">
<id_serie>1</id_serie>
<tipo_programa>Series</tipo_programa>
<episodio>8</episodio>
<temporada>1</temporada>
<titulo >tit1</titulo>
<año>2018</año>
</program>
<program id_programa="6">
<id_serie>2</id_serie>
<tipo_programa>Series</tipo_programa>
<episodio>8</episodio>
<temporada>1</temporada>
<titulo >tit1</titulo>
<año>2018</año>
</program>
<program id_programa="7">
<id_serie>3</id_serie>
<tipo_programa>Series</tipo_programa>
<episodio>8</episodio>
<temporada>1</temporada>
<titulo >tit2</titulo>
<año>2018</año>
</program>
</programs>
</program_file>
With this example what I expect to obtain, in a tabular format, is:
I managed to make a query that gives me the correct results (with BaseX) using Group by:
let $dup_masters := doc("C:/Users/fgarcia/Documents/Optiva/Orange/programs_sample.xml")/program_file/programs
return
<distinct-names> {
for $dups in $dup_masters/program
order by $dups/titulo
group by $title := $dups/titulo
return
if(count(distinct-values($dups[tipo_programa="Master"]/#id_programa)) > 1) then
element {"Master"}
{
attribute {"title"} {$title},
for $id in distinct-values($dups[tipo_programa="Master"]/#id_programa)
return (
<td>{$id}</td>,
<td>{count($dups[id_serie=($id)])}</td>
)
}
else ()
}</distinct-names>
The problem is that when I move this code to Exist-db I obtain no results, and I'm wondering if this can be related to the implementation of Group By in exist. Any ideas/hints on how to solve this in a different manner are welcome!
Related
Hej. I am new at XML-query and have some problem finding a way to combine the result of two xquery into one.
Consider the XML:
<programs>
<program id="488">
<editor>Anna</editor>
<channel>132</channel>
<category>5</category>
</program>
<program id="178">
<editor>Olle</editor>
<channel>132</channel>
<category>68</category>
</program>
<program id="179">
<editor>Olle</editor>
<channel>132</channel>
<category>10</category>
</program>
</programs>
I want to extract list of editors along with the categories they have worked on which would be like this:
<li>Anna 5 </li>
<li>Olle 68 10</li>
Here is the xquery code I am using
let $editors :=
for $d in $sr/sr/programs/program
where $d/channel = "132"
return $d/editor
let $cat :=
for $a in $sr/sr/programs/program
where $a/editor = data($editors)
return concat($a/editor ,' ', $a/category)
for $result in distinct-values($cat)
return <li>{string($result)}</li>
Appreciate all the helps!
I would iterate over the distinct list of editors, obtained from an XPath with a predicate to restrict to those with channel equal to 132, and then retrieve a distinct list of categories for those editors with a similar XPath with predicate filter, and then return the HTML with those values:
for $editor in distinct-values($sr/sr/programs/program[channel eq 132]/editor)
let $categories :=
distinct-values($sr/sr/programs/program[channel eq 132 and editor eq $editor]/category)
return <li>{$editor, $categories}</li>
I have a listPers.xml (TEI List containing persons, obviously ) . I want to write a function to update the listPers.xml
My function looks like this:
declare function app:addPerson($node as node(), $model as map(*)) {
let $person := "<person xml:id=""><persName><forename>Albert</forename><surname>Test</surname></persName></person>"
let $list := doc(concat($config:app-root, '/resources/listPers_test.xml'))
return
update insert $person into $list//tei:listPerson
};
And the listPerson.xml
looks more or less like a typical list with person-entries
I have a tei:header (here omitted) followed by
<text>
<body>
<listPerson xml:id="person">
<person xml:id="abbadie_jacques">
<persName ref="http://d-nb.info/gnd/100002307">
<forename>Jacques</forename>
<surname>Abbadie</surname>
</persName>
<note>Prediger der französisch-reformierten Gemeinde in <rs type="place" ref="#berlin">Berlin</rs>
</note>
</person>
</body>
</text>
</TEI>
(sorry for ruining indentions, it's just an excerpt )
I do not get an error, which means that my app:addPerson should be fine, right?
I want the listPers_test to look like this:
<text>
<body>
<listPerson xml:id="person">
<person xml:id="abbadie_jacques">
<persName ref="http://d-nb.info/gnd/100002307">
<forename>Jacques</forename>
<surname>Abbadie</surname>
</persName>
<note>Prediger der französisch-reformierten Gemeinde in <rs type="place" ref="#berlin">Berlin</rs>
</note>
</person>
<!-- here comes the output that I wish to have :-) -->
<person xml:id=""><persName><forename>Albert</forename><surname>Test</surname></persName></person>
</body>
</text>
</TEI>
In the long run, I aim for an html-form that allows users to input names etc., where ids are generated using sth like
to-lowercase(concat($surname, "_", $forename));
But I will not get into my questions regarding forms and xquery, as I have barely done a quick Google-trip regarding html forms and xquery!
Can anyone hint me at why I do not get the listPers_test.xml file updated with the second value? :-)
All the best and thanks in advance to everyone,
K
Alright, I have a solution for anyone interested in it:
My first snippet $person:= ... contains a STRING, not an element.Changing the line
let $person := "<person xml:id=""><persName><forename>Albert</forename><surname>Test</surname></persName></person>"
to this one actually solves the issue:
let $person := <tei:person xml:id=""><persName><forename>Albert</forename><surname>Test</surname></persName></tei:person>
Using a BizTalk Map and wondering if there's a good way to do the following.
I need to map a received Invoice to a list of Orders. However each Order must contain only two line items (let's assume the Invoice has an even number).
This means that Invoice(1, 2, 3, 4) should map to Orders(Order (1, 2), Order (3, 4)).
Essentially, I need to create new parent elements when (index % 2 == 0).
Is there a functoid-only way of doing this?
XML example below:
<Invoice>
<Client>Client1</Client>
<Line>
<Code>1</Code>
<Price>$1.00</Price>
<Qty>1</Qty>
</Line>
<Line>
<Code>2</Code>
<Price>$2.00</Price>
<Qty>2</Qty>
</Line>
<Line>
<Code>3</Code>
<Price>$3.00</Price>
<Qty>3</Qty>
</Line>
<Line>
<Code>4</Code>
<Price>$4.00</Price>
<Qty>4</Qty>
</Line>
</Invoice>
to
<Orders>
<Order>
<Client>Client1</Client>
<OrderItem>
<Code>1</Code>
<Qty>1</Qty>
</OrderItem>
<OrderItem>
<Code>2</Code>
<Qty>2</Qty>
</OrderItem>
</Order>
<Order>
<Client>Client1</Client>
<OrderItem>
<Code>3</Code>
<Qty>3</Qty>
</OrderItem>
<OrderItem>
<Code>4</Code>
<Qty>4</Qty>
</OrderItem>
</Order>
</Orders>
What I've tried:
Standard mapping: A single Order with all lines, as expected
Value Mapping to Client based on index % 2: Order per line (half have Client)
Table Looping (Gated to index % 2) + Extractor to Client: Order per line, only half lines
What I'm likely to end up doing:
XSLT
Or, C# manipulation after mapping
In the advanced functoids section of the toolbox look for the 'index' functoid.
Add a scripting functoid on the output.
Add C# code to check for the indexes you want to match.
You can switch output on and off by returning a boolean from the scripting functoid.
I have the following xml:
<Root>
<Result img="1.png" name="a">
<Programs>
<Program name="foo1">
<ProgramID>1</ProgramID>
</Program>
</Programs>
</Result>
<Result img="2.png" name="b">
<Programs>
<Program name="foo1">
<ProgramID>1</ProgramID>
</Program>
<Program name="foo2">
<ProgramID>2</ProgramID>
</Program>
</Programs>
</Result>
<Result img="3.png" name="c">
<Programs>
<Program name="foo1">
<ProgramID>1</ProgramID>
</Program>
</Programs>
</Result>
<Result img="4.png" name="d">
<Programs>
<Program name="foo1">
<ProgramID>1</ProgramID>
</Program>
</Programs>
</Result>
</Root>
I am trying to filter xml by ProgramID with below linq statement but i always get no results back when i pass a value of 2, strangely when i pass a value of 1 in I do get expected results back which is all four results.
xOut = New XElement("Root", _
From s In x...<Result> _
Where s.<Programs>.<Program>.<ProgramID>.Value = 2 _
Select s)
What is wrong with linq query. Why does a 1 work but a 2 does not? I would also like xml structure preserved after filtering.
Here's how you'd do it in C#:
var xOut = new XElement(
"Root",
x.Descendants("Result")
.Where(y => y.Descendants("Programs").Descendants("Program").Descendants("ProgramID")
.Any(z => z.Value == "2")));
Not sure what the VB.NET equivalent would be though, sorry.
i'm getting the xmldata from the httpservice (using cgi) and i have not set resultformat(it is coming as an object only),the xml data in this format
<root>
<employee name="xxx" age="xx" gender="xxx"/>
<employee name="xxx" age="xx" gender="xxx"/>
<employee name="xxx" age="xx" gender="xxx"/>
</root>
when i was tried to count the employee tag,i getting the problem, my code will like this:
var i:int=o;
for each(var obj:object in event.result.root.employee)
{
i++;
}
i getting the count as 3 but the problem it give the count as 3 when the coming data i.e)the xml data is
<root>
<employee name="xxx" age="xx" gender="xxx"/>
<root>
actually i want to count the number of employees tag not all subtag ,
i hope you may save my time
Thanks in advance..
event.result.employee.length()
or look here for .ChildNodes
http://www.republicofcode.com/tutorials/flash/xml/
or another one
http://www.underground-flash.com/2008/02/arraylength-vs-xmllength-in-as3.html
and one more professional
http://www.thetechlabs.com/tutorials/xml/working-with-xml-e4x-and-actionscript-3/