UCM - How to access repeat children nodes from XML - idocscript

I've got an XML document -
<PARTNER>
<CompanyName>ABCD<CompanyName>
<Address>XYZ</Address>
<OFFER>
<OFFERNAME>ABCDEFG</OFFERNAME>
<OFFERDESC>XYZWV</OFFERDESC>
</OFFER>
<OFFER>
<OFFERNAME>123456</OFFERNAME>
<OFFERDESC>98765</OFFERDESC>
</OFFER>
</PARTNER>
I want to access the individual OFFERNAME, OFFERDESC elements from each of the OFFER
tags.
<!--$ssIncludeXml("dDocName","wcm:root/wcm:element[#name="OFFER"]/node()")-->
Gives me the entire ABCDEFG XYZWV 123456 98765 which I do not want. Is there a
way I can access OFFERNAME, OFFERDESC from each of the OFFER tags?
PS: I have 2 OFFER nodes and each of them has 17 children nodes. When I try
<!--$ssGetXmlNodeCount("dDocName", "wcm:root/wcm:element[#name='OFFER']/node()")-->, I
get 34.
<!--$ssIncludeXml("dDocName","wcm:root/wcm:element[#name="OFFER"][1]/node()")--> prints
nothing.

Related

Select XML Node by position

I have the following XML structure
<Root>
<BundleItem>
<Item>1</Item>
<Item>2</Item>
<Item>3</Item>
</BundleItem>
<Item>4</Item>
<Item>5</Item>
<Item>6</Item>
<BundleItem>
<Item>7</Item>
<Item>8</Item>
<Item>9</Item>
</BundleItem>
</Root>
And by providing the following xPath
//Item[1]
I am selecting
<Item>1</Item>
<Item>4</Item>
<Item>7</Item>
My goal is to select only <Item>1</Item> or <Item>7</Item> regardless of the parent element where they are found and only depending on the position, which i am providing in the xPath.
Is it possible to do that only by using the position and without providing additional criterias in the xPath ?
//Item[1] selects the all the first child elements that are <Item/> regardless of their parent.
To get the two items you are looking for you could use //Item[text() = 1 or text() = 7].
A good tutorial can be found at w3schools.com and you can play with XPath expressions over your XML input here. (I am not affiliated with either of these resources but find them useful.)

XPATH How to Select two specific chidren from a same parent

Good night, friends!
Lets suppose we have a xml with 30 items like that and I want to get just the name and url from an item where name contains the word: Richard.
<channel>
<item>
<name>Brian</name>
<lastname>Connor</lastname>
<age>40</age>
<enclosure url="http://www.brian.com"/>
</item>
<item>
<name>Richard</name>
<lastname>Wendell</lastname>
<age>38</age>
<enclosure url="http://www.richard.com"/>
</item>
</channel>
How can I do that using XPath?
I tried:
"//channel/item[name[contains(text(),'Richard')]]" but it returns just the name and I don't know how to select the url information together.
Please excuse my english!
Your approach does not work because you are selecting a sub tree (in this case an item) of the XML tree which contains more information than you want. If you want just a subset of the attributes in ONE xpath expression you have to select them separately and then concatenate them adequately, e.g.
concat('name=', //channel/item[contains(name, 'Richard')]/name, ' url=', //channel/item[contains(name, 'Richard')]/enclosure/#url)
The example will allow you to alter the additional formatting easily.
By the way: your XML input was malformatted. I corrected this.

Summing XML Data in MSWord Mail Merge

I have a report card written in Word that uses an XML file for its input. In the XML file, if a student remains in the same section all three trimesters there will be one node for that class; if they change sections at the trimester they'll have one node for each section. The nodes look something like this (greatly simplified):
<ReportCardSectionFB Abs1="2" Abs2="11" CourseID="ELMATH1" CourseTitle="Math" PeriodStart="3" TeacherName="Jones, Jennifer" TermCode="Year" SectionID="ELMATH1-4" />
<ReportCardSectionFB Abs1="1.50" Abs2="6" CourseID="ELMATH1" CourseTitle="Math" PeriodStart="3" TeacherName="Smith, Tina" TermCode="Year" SectionID="ELMATH1-3" />
There is no indicator within the XML as to which trimester the node belongs to.
In the Word document, we're pulling the absence data with the following mail merge command:
{MERGEFIELD "ReportCardSectionFB[#PeriodStart='3']/ #Abs1" \# 0.# \* MERGEFORMAT }
That's not working in this situation: it only gets the absence data from the first node it comes across, i.e.: 2.0. Is there a way to get the sum of #Abs1 for all period 3 classes, i.e.: 3.5? If not, is there a way to only get the last #Abs1 for period 3, i.e.: 1.5?
I recommend you to use this 3rd party product, which can use xml as input and is capable of merging it with MS Word template. I is also much more powerful than the built-in Word's mail merge. You can see some examples here.
You could also try summing the absences in Synergy - there's a new checkbox under AttDef1, 2, etc. that adds up all the absences for the data range - Include all day data for the entire date range regardless of section enrollment or section timeframe. That way the absences should be the same for each section, if that works for your district.
You can also try the SET function in Word to nest the MERGEFIELDS as bookmarks and use the Word operator functions to then add the bookmarks.

Template nested grouping with Sort option

I would like to generate a report using RTF Template which looks like the below:
Expected Output:
US
Cover Insured
123456 INS1, INSB, INSA
987654 INS2
or
US
Cover Insured
123456 INS1
INSB
INSA
987654 INS2
Here "Insured" data is present both in Parent and child hierarchy with different tag names. Parent "InsuredAccnt" (INS1 in my XML) should be displayed first followed by child "InsuredAccounts" which will be sorted by "Share" - Descending.
XML:
<?xml version="1.0" encoding="UTF-8" ?>
<InsuredReport>
<GroupPolicies>
<Cover>123456</Cover>
<Customer>Customer</Customer>
<InsuredAccnt>INS1</InsuredAccnt>
<Organization>US</Organization>
<ListOfGroupPolicies_InsuredAccount>
<GroupPolicies_InsuredAccount>
<InsuredAccount>INSA</InsuredAccount>
<Share>5</Share>
</GroupPolicies_InsuredAccount>
<GroupPolicies_InsuredAccount>
<InsuredAccount>INSB</InsuredAccount>
<Share>20</Share>
</GroupPolicies_InsuredAccount>
</ListOfGroupPolicies_InsuredAccount>
</GroupPolicies>
<GroupPolicies>
<Cover>987654</Cover>
<Customer>ABC</Customer>
<InsuredAccnt>INS2</InsuredAccnt>
<Organization>US</Organization>
<ListOfGroupPolicies_InsuredAccount />
</GroupPolicies>
</InsuredReport>
I am not sure how to upload the RTF used, but this is a gist of the same:
RTF:
<?for-each-group:GroupPolicies;./Organization?>
Grouping within Table based on Cover
<?for-each-group:current-group();./Cover?>
Displaying "Insured"
<?InsuredAccnt?>
<?for-each-group:current-group();./GroupPolicies_InsuredAccount?><?sort: Share?><?InsuredAccount?><?end for-each-group?>
When I give this, my system runs forever and I am forced to kill the session.
Please could someone point out where I am wrong.
I was able to achieve the desired using the following:
<?InsuredAccnt?>
<?for-each:GroupPolicies_InsuredAccount?><?sort:Share;'descending';data-type='number'?><?InsuredAccount?><?end for-each?>
The Current-Group() tag was not needed a second time. This produces Output # 2, i.e displaying the "InsuredAccounts" one after the other.

XPATH - get all <tag> text data except the last two <tag>

This is my HTML data
<book></book>
<book></book>
<book></book
....
....
'N' books
I'd like to get all the text data between all the <book></book> nodes except the last 2 <book> nodes
Basically i need //book[1 to n-2]//text()
Is there an XPATH query i can write for this?
One possible way to get all book elements within the same parent, except the last two book elements (in other words, excluding the last and one before the last) :
//book[position() < last()-1]

Resources