How to unique values from different nodes in xslt - xslt-3.0

I have below xml
input:
<Records count="1">
<Record contentId="2410630" levelId="442" levelGuid="29c1b6a4-b7db-49dc-a703-e78aa1b1246a" moduleId="875" parentId="0">
<Record contentId="2410631" levelId="458" levelGuid="67dbf848-5352-4953-a25b-1b1bbcde89be" moduleId="891" parentId="0">
<Record contentId="2208294" levelId="330" levelGuid="d25cfb04-eb2a-423c-bdab-2db21a58fd4d" moduleId="675" parentId="0">
<Field id="31799" guid="2ebbfd8e-3e89-4be5-9c1f-1b5e85950753" type="1">Unauthorized modification of Information/System - External</Field>
<Field id="31796" guid="24640c19-d1de-415b-b349-25b0af521373" type="6">2208294</Field>
</Record>
</Record>
<Record contentId="2410632" levelId="458" levelGuid="67dbf848-5352-4953-a25b-1b1bbcde89be" moduleId="891" parentId="0">
<Record contentId="2208289" levelId="330" levelGuid="d25cfb04-eb2a-423c-bdab-2db21a58fd4d" moduleId="675" parentId="0">
<Field id="31799" guid="2ebbfd8e-3e89-4be5-9c1f-1b5e85950753" type="1">Inadequate Information Security Practices</Field>
<Field id="31796" guid="24640c19-d1de-415b-b349-25b0af521373" type="6">2208289</Field>
</Record>
</Record>
<Record contentId="2410633" levelId="458" levelGuid="67dbf848-5352-4953-a25b-1b1bbcde89be" moduleId="891" parentId="0">
<Record contentId="2208270" levelId="330" levelGuid="d25cfb04-eb2a-423c-bdab-2db21a58fd4d" moduleId="675" parentId="0">
<Field id="31799" guid="2ebbfd8e-3e89-4be5-9c1f-1b5e85950753" type="1">Loss of Systems Including Data Center</Field>
<Field id="31796" guid="24640c19-d1de-415b-b349-25b0af521373" type="6">2208270</Field>
</Record>
</Record>
<Record contentId="2410636" levelId="458" levelGuid="67dbf848-5352-4953-a25b-1b1bbcde89be" moduleId="891" parentId="0">
<Record contentId="2208289" levelId="330" levelGuid="d25cfb04-eb2a-423c-bdab-2db21a58fd4d" moduleId="675" parentId="0">
<Field id="31799" guid="2ebbfd8e-3e89-4be5-9c1f-1b5e85950753" type="1">Inadequate Information Security Practices</Field>
<Field id="31796" guid="24640c19-d1de-415b-b349-25b0af521373" type="6">2208289</Field>
</Record>
</Record>
<Record contentId="2410661" levelId="463" levelGuid="cc59604e-cc41-4253-879a-5fbde3ffd760" moduleId="896" parentId="0">
<Field id="41541" guid="bae76db7-4e46-4113-a453-68243a76d4f6" type="9">
<Reference id="2208289">Inadequate Information Security Practices</Reference>
</Field>
</Record>
<Record contentId="2410666" levelId="463" levelGuid="cc59604e-cc41-4253-879a-5fbde3ffd760" moduleId="896" parentId="0">
<Field id="41541" guid="bae76db7-4e46-4113-a453-68243a76d4f6" type="9">
<Reference id="2208273"> Loss of 50% Staff </Reference>
</Field>
</Record>
<Record contentId="2410649" levelId="462" levelGuid="83a26d99-e79d-41af-8a20-fa069f791cef" moduleId="895" parentId="0">
<Field id="41453" guid="9a764db7-a75e-4a49-9b26-de03e2bc4bb5" type="9">
<Reference id="2208328">Technology Configuration</Reference>
</Field>
</Record>
</Record>
</Records>
Expected Output:
<uniqueValues>Inadequate Information Security Practices</uniqueValues>
<uniqueValues>Loss of Systems Including Data Center</uniqueValues>
<uniqueValues>Loss of 50% Staff</uniqueValues>
<uniqueValues>Technology Configuration</uniqueValues>
Here is my code
<xsl:stylesheet version="3.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl">
<xsl:output method="xml" indent="yes"/>
<xsl:output method="xml"/>
<xsl:variable name ="fields" select="//Metadata/FieldDefinitions" />
<!--match the root node-->
<xsl:template match="Records">
<ArcherRecords>
<xsl:for-each select="Record[#levelGuid='29c1b6a4-b7db-49dc-a703-e78aa1b1246a']">
<xsl:variable name="valuesTobeCompared" select="Record/Field[#guid='bae76db7-4e46-4113-a453-68243a76d4f6']/Reference/#id"/>
<xsl:for-each-group select="Record/Record" group-by="./Field[#guid='24640c19-d1de-415b-b349-25b0af521373']">
<xsl:choose>
<xsl:when test="$valuesTobeCompared = ./Field[#guid='24640c19-d1de-415b-b349-25b0af521373']">
</xsl:when>
<xsl:otherwise>
<uniqueValues><xsl:value-of select="./Field[#guid='24640c19-d1de-415b-b349-25b0af521373']"/></uniqueValues>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each-group>
</xsl:for-each>
</ArcherRecords>
</xsl:template>
</xsl:stylesheet>
but it is only giving first set of unique values but I want all unique values from entire record set along with it should also have one value of duplicated value, I was not sure how to get all node values into one variable I am able to store only one node values into variable,
Could anybody help me how to write a xslt code to get the unique values
group-by itself will retrieve unique values from provided selectpath, but how can I give multiple node-set values to for-each-group

Related

FIX 4.4 FieldNotFound: Field not found

I receive the following message from counterparty:
8=FIX.4.4|9=219|35=W|34=4|49=id|52=20200618-14:34:20.738|56=id1|42=20200618-14:34:20.688|55=EUR/USD|262=1|268=2|269=0|270=1.12083|271=500000|269=1|270=1.12084|271=500000|10094=2020.06.18 14:34:20.688|10=141|
The message contains the field 268 = 2, and both groups begin with the field 269, and I am trying to extract fields 270. My code looks like this:
message= quickfix.Message('8=FIX.4.4\x019=219\x0135=W\x0134=4\x0149=id\x0152=20200618-14:34:20.738\x0156=id1\x0142=20200618-14:34:20.688\x0155=EURUSD\x01262=1\x01268=2\x01269=0\x01269=1\x01270=1.12083\x01270=1.12084\x01271=500000\x01271=500000\x0110094=2020.06.18 14:34:20.688\x0110=141\x01')
group = quickfix44.MarketDataSnapshotFullRefresh.NoMDEntries()
fix_no_entries = quickfix.NoMDEntries()
message.getField(fix_no_entries)
no_entries = fix_no_entries.getValue() # print = 2 as expected
message.getGroup(1, group)
However, when running the getGroup line, I get the error:
FieldNotFound: Field not found
Any idea on what is going wrong?
Thank you again guys!
Quickfix doesn't know about your message structure, so you need to provide some info about how to parse the message, otherwise it's just a bunch of fields without groups.
<message>
<header>
<field number="8"><![CDATA[FIX.4.4]]></field>
<field number="9"><![CDATA[183]]></field>
<field number="35"><![CDATA[W]]></field>
<field number="34"><![CDATA[4]]></field>
<field number="49"><![CDATA[id]]></field>
<field number="52"><![CDATA[20200618-14:34:20.738]]></field>
<field number="56"><![CDATA[id1]]></field>
</header>
<body>
<field number="42"><![CDATA[20200618-14:34:20.688]]></field>
<field number="55"><![CDATA[EURUSD]]></field>
<field number="262"><![CDATA[1]]></field>
<field number="268"><![CDATA[2]]></field>
<field number="269"><![CDATA[0]]></field>
<field number="269"><![CDATA[1]]></field>
<field number="270"><![CDATA[1.12083]]></field>
<field number="270"><![CDATA[1.12084]]></field>
<field number="271"><![CDATA[500000]]></field>
<field number="271"><![CDATA[500000]]></field>
<field number="10094"><![CDATA[2020.06.18 14:34:20.688]]></field>
</body>
<trailer>
<field number="10"><![CDATA[182]]></field>
</trailer>
</message>
Quickfix data dictionaries are the way to configure the message parser. Quickfix already comes along with some pre-configured dictionaries, you can customize it according with your needs.
data_dictionary = quickfix.DataDictionary("quickfix/FIX44.xml")
message= quickfix.Message('...', data_dictionary, True)
print(message.toXML())
Now the message is structured and it's possible to retrieve groups data:
<message>
<header>
<field number="8"><![CDATA[FIX.4.4]]></field>
<field number="9"><![CDATA[183]]></field>
<field number="35"><![CDATA[W]]></field>
<field number="34"><![CDATA[4]]></field>
<field number="49"><![CDATA[id]]></field>
<field number="52"><![CDATA[20200618-14:34:20.738]]></field>
<field number="56"><![CDATA[id1]]></field>
</header>
<body>
<field number="42"><![CDATA[20200618-14:34:20.688]]></field>
<field number="55"><![CDATA[EURUSD]]></field>
<field number="262"><![CDATA[1]]></field>
<field number="268"><![CDATA[2]]></field>
<field number="10094"><![CDATA[2020.06.18 14:34:20.688]]></field>
<group>
<field number="269"><![CDATA[0]]></field>
</group>
<group>
<field number="269"><![CDATA[1]]></field>
<field number="270"><![CDATA[1.12083]]></field>
</group>
<group>
<field number="270"><![CDATA[1.12084]]></field>
<field number="271"><![CDATA[500000]]></field>
</group>
<group>
<field number="271"><![CDATA[500000]]></field>
</group>
</body>
<trailer>
<field number="10"><![CDATA[182]]></field>
</trailer>
</message>

How to create odoo 12 website submenu through code?

I would like to create submenu under About Us main menu. I am trying with following code but it is adding main menu.
<!-- Main Menu ABOUT US -->
<record id="menu_about_us" model="website.menu">
<field name="name">ABOUT US</field>
<field name="page_id" ref="about-us" />
<field name="parent_id" ref="website.main_menu" />
<field name="sequence" type="int">10</field>
</record>
<!-- Sub Menu Under ABOUT US -->
<record id="menu_board_and_founders" model="website.menu">
<field name="name">BOARD AND FOUNDERS</field>
<field name="page_id" ref="board-and-founders" />
<field name="parent_id" ref="menu_about_us" />
<field name="sequence" type="int">10</field>
</record>

Ir.rule model for diferent groups odoo

I want to make different ir.rule models for different group of users
I have make the rule and work okay but dont know how to assign the group.
<record model="ir.rule" id="pupils_rule">
<field name="name">Tutor only view his pupils</field>
<field name="model_id" ref="model_res_users"/>
<field name="domain_force">[('tutor','=',user.id)]</field>
<field name="perm_read" eval="True"/>
<field name="perm_create" eval="False"/>
<field name="perm_write" eval="False"/>
<field name="perm_unlink" eval="False"/>
</record>
My 2 security group group_tutor and group_pupil. Mymodel.acess.csv if u need something of the group.
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
tutor_activity,Model pupil
access,model_proyectosge_activity,group_tutor,1,0,0,0
pupil_activity,Model pupil
access,model_proyectosge_activity,group_pupil,1,1,1,1
you to have to add a line like
<field name="groups" eval="[(4, ref('XML ID OF TUTORS'))]"/>
as in the fourth line in the following
<record model="ir.rule" id="pupils_rule">
<field name="name">Tutor only view his pupils</field>
<field name="model_id" ref="model_res_users"/>
<field name="groups" eval="[(4, ref('XML ID OF TUTORS'))]"/>
<field name="domain_force">[('tutor','=',user.id)]</field>
<field name="perm_read" eval="True"/>
<field name="perm_create" eval="False"/>
<field name="perm_write" eval="False"/>
<field name="perm_unlink" eval="False"/>
</record>

add an element to a node, if it doesnot exist, based on matching criteria

Using XSLT 3.0,
I have as input the following XML:
<?xml ="1.0" encoding="UTF-8"?>
<TABLE NAME="TABLE.DB">
<DATA RECORDS="2">
<RECORD ID="1">
<RECNO>1</RECNO>
<SEQ>0</SEQ>
<DATE>17/12/1999 2:44:08 μμ</DATE>
<ID>12/11/2015 3:15:25 μμ</ID>
<ORDER>10355</ORDER>
<CN>PL</CN>
<PROPERTY>06</PROPERTY>
</RECORD>
<RECORD ID="2">
<RECNO>2</RECNO>
<SEQUENCE>0</SEQUENCE>
<DATE>17/12/1999 2:44:08 μμ</DATE>
<ID>12/11/2015 3:15:25 μμ</ID>
<ORDER>000026672</ORDER>
<CN>PL 300 L</CN>
</RECORD>
<RECORD ID="3">
<RECNO>3</RECNO>
<SEQUENCE>0</SEQUENCE>
<DATE>17/12/1999 2:44:08 μμ</DATE>
<ID>12/11/2015 3:15:25 μμ</ID>
<NUMBER>10357</NUMBER>
<CN>PL 300 L</CN>
<PROPERTY>0</PROPERTY>
</RECORD>
</DATA>
</TABLE>
given values used for matching:
(i use \t to define the tab separated nature of my input file)
"10355"\t"PL"
"000026672"\t"PL 300 L"
i need to insert to all records that do not already have a PROPERTY tag, with the value of 06
Desired result:
<?xml ="1.0" encoding="UTF-8"?>
<TABLE NAME="TABLE.DB">
<DATA RECORDS="2">
<RECORD ID="1">
<RECNO>1</RECNO>
<SEQ>0</SEQ>
<DATE>17/12/1999 2:44:08 μμ</DATE>
<ID>12/11/2015 3:15:25 μμ</ID>
<ORDER>10355</ORDER>
<CN>PL</CN>
<PROPERTY>06</PROPERTY>
</RECORD>
<RECORD ID="2">
<RECNO>2</RECNO>
<SEQUENCE>0</SEQUENCE>
<DATE>17/12/1999 2:44:08 μμ</DATE>
<ID>12/11/2015 3:15:25 μμ</ID>
<ORDER>000026672</ORDER>
<CN>PL 300 L</CN>
<PROPERTY>06</PROPERTY>
</RECORD>
<RECORD ID="3">
<RECNO>3</RECNO>
<SEQUENCE>0</SEQUENCE>
<DATE>17/12/1999 2:44:08 μμ</DATE>
<ID>12/11/2015 3:15:25 μμ</ID>
<NUMBER>10357</NUMBER>
<CN>PL 300 L</CN>
</RECORD>
</DATA>
</TABLE>
What i have tried, adds the element property, even if it is already there, so i end up with two elements PROPERTY, in the same node, if it already exists. Could you give me an example implementation, i use SAXON latest release (9.8)
xsl: which adds an element, even when one exists:
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:exsl="http://exslt.org/common" exclude-result-prefixes="xsl exsl xs">
<xsl:output method="xml" version="1.0" indent="yes" encoding="utf-8" />
<xsl:template match="#*|node()">
<xsl:copy>
<xsl:apply-templates select="#*|node()" />
</xsl:copy>
</xsl:template>
<xsl:template match="//*[local-name() = 'RECORD ID']">
<xsl:copy>
<xsl:apply-templates select="#* | node()"/>
<xsl:choose>
<xsl:when test="not(PRODUCT)">
<PRODUCT><xsl:value-of select="98"/></PRODUCT>
</xsl:when>
<xsl:otherwise>
<xsl:copy><xsl:value-of select="98"/></xsl:copy>
</xsl:otherwise>
</xsl:choose>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
Have been using the solution suggested with my real data, (which differ a lot from the example), and i face the following issue:
How could i also have a report that would let me know, which of the additions while they were to be done, according to the input file, were not inserted?
A few observations:
(a) in your sample output, the PROPERTY element has been deleted from record 3. I can't see anything in your description of requirements that explains why.
(b) in your requirements statement, the sentence "i need to insert to all records that do not already have a PROPERTY tag, with the value of 06" is ambiguous. I would read this as saying that if there is a PROPERTY 'tag' (correctly, element) with a value other than 06 then you should insert another PROPERTY element, but that seems to contradict what you say elsewhere.
(c) your code has a template rule with match="//*[local-name() = 'RECORD ID']". You can delete the "//" at the start of a match pattern, it's redundant. More importantly, no element will ever have a local name equal to "RECORD ID" - element names cannot include spaces. So the template rule will never match anything.
(d) assuming that this template rule was intended to match RECORD elements, you certainly don't want the xsl:copy inside the xsl:otherwise, as this will create a nested copy of the whole RECORD.
(e) you've asked for an XSLT 3.0 solution but there's nothing in your problem that requires XSLT 3.0, and in fact your own stylesheet says version="2.0".
(f) I can't see what role the tab-separated parameter file plays in any of this.
In short, there's an awful lot of clarification needed before anyone can start to write any code.
Your solution requires a few changes:
The template shoud match RECORD, not RECORD ID (ID is an
attribute which takes no part in any decision).
Your general concept is OK:
copy the starting tag (<RECORD>),
apply templated to the inside of the current RECORD,
check whether PROPERTY (not PRODUCT) element is absent (in the
current RECORD),
if it is (absent), then output PROPERTY element with the required value,
copy the closing tag (</RECORD>).
I removed the otherwise part (not needed) and changed choose to
a single if..
As you specified XSLT 3.0, even the identity template can be
replaced with (a bit shorter) on-no-match="shallow-copy".
I also added version to your source XML. Otherwise it is not well-formed.
So the whole script can look like below:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="3.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:mode on-no-match="shallow-copy"/>
<xsl:template match="RECORD">
<xsl:copy>
<xsl:apply-templates select="#* | node()"/>
<xsl:if test="not(PROPERTY)">
<PROPERTY>06</PROPERTY>
</xsl:if>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
Tested on http://xsltfiddle.liberty-development.net/

Can you do a partial search on numbers in Odoo?

I have a search view created:
<record model="ir.ui.view" id="helpdesk_ticket_search_view">
<field name="name">helpdesk.ticket.search.view</field>
<field name="model">helpdesk.ticket</field>
<field name="arch" type="xml">
<search string="Owner Search">
<filter string="Owner" name="res_users" domain="[('res_users_id', '=', 'uid')]"/>
<field name="res_users_id"/>
<field name="name"/>
<field name="ticketnumber" />
<group string="Group by">
<filter string="Owner" name="res_users" domain="[]"
context="{'group_by':'res_users_id'}"/>
</group>
</search>
</field>
</record>
When I search by user, I don't need to type the full name out eg. instead of typing "user", I can just type "us" and get a list
However, with numbers if I am looking for "12345678" I have to type it all out and not just "123".
Is it possible to search for numbers just using part of the number? This is helpful to me with a helpdesk when i am looking for all ticket starting with 123.
Any advise?

Resources