InDesign CS6 Check the XML document for specific attribute - adobe-indesign

I have an xml file with the attribute style inside the resultset
<resultset statement="select adtext from ad where adCategoryID=3 order by adinsertdate desc limit 100" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" style="cars">
The value of the attribute may vary in different xml files, so I would like to get the value of the attribute and apply the corresponding styling to my xml, according to this value.
However no matter what variations I try in this statement:
if(myTemplate.XMLElement.XMLAttributes.itemByName("style").value == "cars"){//...}
I get the following message:
"Object does not support the property or method 'XMLElement'.
Any help will be appreciated.

Related

Adress div in XPath with nested properties inside this div

we want to automate an web application with Robot framework/SeleniumLibrary. The app contains some tables, which do not have simple unique identifiers like id/name/class... They only can be uniquely identified via a nested property. Here a sample excerpt of the properties window (DevTools)
grid: window.<computed>
> FormSubmitOnlyChanged : true
> ...
> _dataprocessor: dataProcessor
> autoUpdate: false
> ...
> serverProcessor: "/TEST/GridNew/multi?group=getMetaData&name=Sources&editing=true"
> ...
> ...
...
The Element looks as following:
* The id parameter contains an dynamic id and can therefore not be used for object identification.
We tried some approaches, e.g.
//div[contains(#grid._dataprocessor.serverProcessor, 'group=getMetaData&name=Sources')]
or
//div[contains(#serverProcessor, 'group=getMetaData&name=Sources')]
but none of them did work. Does anybody have an idea how to get an XPath that makes it possible to contain the nested property? Thank you in advance.
Please try this XPath:
"//div[contains(., 'group=getMetaData&name=Sources')]"
The dot . means here any attribute containing group=getMetaData&name=Sources value.
Also, I see the parent element in the shared picture is hidden. Maybe this causes your problems?
Please try this below xpath:
//div[starts-with(#id,'cgrid2_')]
The developers now managed it to set an id manually to overwrite the generated dynamic ID. Furthermore, after more research, it seems to be not possible to use this property for XPath.

xpath to select namespace from xml document

Using xslt 1.0 (BizTalk 2016) I'm looking for a generic way to select the namespace of any valid xml document
For example, I have the following xml document:
<?xml version="1.0" encoding="utf-8"?>
<PortfolioActivation xmlns="http://www.random.com/bo/request/portfolioactivation">
<Portfolio>
<ExternalId>PRT-00000450</ExternalId>
<InternalId>c8b0239c-1e98-e911-a8b1-00224800449b</InternalId>
<Version>8627558</Version>
<Type>001</Type>
</Portfolio>
</PortfolioActivation>
Given that the Root element value could be anything, what would be the xpath to select the value of the namespace i.e http://www.random.com/bo/request/portfolioactivation
I had hoped "/*/#xmlns" would work but it doesn't.
The namespace of the outermost element can be found using namespace-uri(/*).
Alternatively, the default namespace that's in scope for the outermost element is /*/namespace::*[name()=''].
These aren't the same thing. Consider
<p:root xmlns="a.ns" xmlns:p="b.ns"/>
The first expression will give you "b.ns", the second will give you "a.ns". It's not clear from your question which you want.
Note that namespaces are not attributes in the XDM data model, so you never access them using the attribute axis. #xmlns will therefore never work.

XPath expression to pluck out attribute value

I have the following XML:
<envelope>
<action>INSERT</action>
<auditId>123</auditId>
<payload class="vendor">
<fizz buzz="3"/>
</payload>
</envelope>
I am trying to write an XPath expression that will pluck out vendor (value for the payload's class attribute) or whatever its value is.
My best attempts are:
/dataEnvelope/payload[#class="vendor"]#class
But this requires the expression to already know that vendor is the value of the attribute. But if the XML is:
<dataEnvelope>
<action>INSERT</action>
<auditId>123</auditId>
<payload class="foobar">
<fizz buzz="3"/>
</payload>
</dataEnvelope>
Then I want the expression to pluck out the foobar. Any ideas where I'm going awry?
If you need #class value from payload node, you can use
/dataEnvelope/payload[#class]/#class
or just
/dataEnvelope/payload/#class
At first, your two XML files are out-of-sync - one references envelope and the other references dataEnvelope. So exchange one for the other, if necessary.
So, to get the attribute value of payload, you can use an XPath expression like this which uses a child's attribute value to be more specific:
/envelope/payload[fizz[#buzz='3']]/#class
Output is:
vendor
If the document element can/will change, then you can keep the XPath more generic and select the value of the class attribute from the payload element that is a child of any element:
/*/payload/#class
If you know that it will always be a child of envelope, then this would be more specific(but the above would still work):
/envelope/payload/#class

assign value from attribute_view_gui from select attribute

I have an attribute if type select. When i try to get value from this attribute content it gives the identification number instead of the value. I call like
$node.data_map.my_attribute_identifier.content
This is expected behaviour. https://doc.ez.no/eZ-Publish/Technical-manual/4.x/Reference/Datatypes/Selection
Raw output
The ".content" of an ezcontentobjectattribute object using this datatype returns an array of the identification numbers (as strings) of the selected options.
I want the value not the identification number. I can get that using attribute_view_gui like
attribute_view_gui attribute=$node.data_map.my_attribute_identifier
But i can't assign value to a variable this way. How can i assign value from a select attribute?
First of all i recommend you to always check default templates in your ezpublish to figure out how should template look...
Maybe this example will help:
<input
id="whatever_id_you_like"
type="text" size="50"
name="ContentObjectAttribute_ezstring_data_text_{$node.object.data_map.YOUR_ATTRIBUTE_SHORT_NAME.id}"
value="{$YOUR_VAR}"
/>
or u can use default view for attribute like this:
{attribute_view_gui attribute=$node.data_map.YOUR_ATTRIBUTE_SHORT_NAME}
also might be helpful - way to find correct path (sometimes you need add ".data_int" or ".data_text" on the end of the path to display data):
{$path|attribute(show,depth)} example:
{$node|attribute(show,2)}
or
{$YOUR_FANCY_VAR.content|attribute(show,2)}
You may want to take a look at the view template of ezselection:
ezselection.tpl
This is the code that eZ Publish uses to view the data type.
content of ezselection.tpl:
{let selected_id_array=$attribute.content}
{section var=Options loop=$attribute.class_content.options}
{section-exclude match=$selected_id_array|contains( $Options.item.id )|not}
{$Options.item.name|wash( xhtml )}{delimiter}<br/>{/delimiter}{/section}
{/let}

How to internationalize a collection's conversion error message in Struts2?

A related problem that is specific to single field has been solved here. But how to customize a collection field's conversion error message?
Here is an example:
On a jsp page, I have a field in Collection type:
...
<s:iterator value="items" status="m">
<s:hidden name="selitmems[%{#m.index}].id" value="%{id}"/>
<s:textfield name="selitmems[%{#m.index}].quant" size="10"/>
</s:iterator>
The items' type is: List<Item>; the selitems' type is List<SelItem>.
I want selitmems[].quant property to be an integer type. If a string like "abc" is filled in for the first item by an end user, the default error message is:
Invalid field value for field "selitmems[0].quant".
The above message is not what i want. In my case, I would prefer to generalize the error message as follows regardless of the specific selected item:
Please input integers for the items.
Of course it would be great if the error message can vary according to the specific item:
Please input an integer for the first item.
I have tried to add some keys like "selitmems[0].quant" or "selitmems" in the properties file, but can't get the result. Is there way to customize the error message for a collection field in struts2 when I can still reuse the built-in type conversion functions?
Try using the "label" attribute. You can play some... interesting games with this, such as (untested, but close):
label="%{getText('selitem.quantity', { #m.index })}"
The property file would contain:
selitem.quantity=Item #{0}
You can change the conversion error message as described here, although this may not be precisely what you want to do.
(I've been known to remove the conversion interceptor altogether and let either the default converters or custom converters handle conversion errors when a bad conversion also fails the field's "real" validation.)
Mm hmm... you can play some crazy games with OGNL and substituion.
Put something like this in your properties file.
invalid.fieldvalue.selitmems.quant = Please input integers for the items.
Then selitmems[0].quant, selitmems[1].quant, selitmems[2].quant conversion errors all return the same message.

Resources