I want to address an xml value in the Xpath field within the enrich mediator in order to customize an API response. My xml input is as follow:
<member>
<name>ABC</name>
</value>1</value>
</member>
I tried to access the 'ABC' value by using this code:
$body//member[#name='ABC']
but it does not work for me.
First of all your XML input is not valid. There is no opening value tag but two closing.
Can you try //member/name/text(),this worked für me.If its not working,then maybe you need to add the namespaces.
Hope that helps.
Related
This may be somewhat naive but I am quite struck on the issue
There is a specific <result> element in DataPower and when calling through xslt we have somewhat following format(which I discovered in some forums)--
<results mode="require-all" multiple-outputs="true" transactional="true" retry-interval="100" asynchronous="false">
<url input="var://the_request_SOAP_Format"asynchronous="true">https://XXXXXXX</url>
now in this (url input) is the request which needs to be send and (https://XXXXXXX) is the specified backend where it needs to be sent
Now I have some authentication headers(httpHeaders) also which I need to send without which I will get Authorization error
<xsl:variable name="httpHeaders">
<header name="Content-Type">application/json</header>
<header name="Authorization">
<xsl:value-of select="concat('Bearer ',$some_sessionID)"/>
</header>
</xsl:variable>
Is this possible to add these 'httpHeaders' in the result mode element/Tab property
Thanks
I am not exactly sure what you are trying to achieve but adding http headers for the response (backside) you do with:
<dp:set-http-response-header name="'HeaderName'" value="$httpHeaders"/>
or
<dp:set-http-request-header name="'HeaderName'" value="$httpHeaders"/>
The <results> is the collection of data that the Processing Policy will output as Payload for the Request/Response and won't contain headers. You shouldn't try to alter the <results> object!
The "results-doc" method of calling backends is quite powerful, but I'm not sure from your question if you fully understand it. The url/#input attribute needs to be a DataPower context:
<url input="var://context/mycontext" ...
To associate headers with that context, you should do something like this for each header you need:
<dp:set-variable
name="'var://context/mycontext/_extension/header/Content-Type'"
value="'application/json'"/>
(This would be done in your XSLT code, separate from creating the "results" document, but before you use a Results Action to execute.)
How to add inner attribute to spring REST webservice response?
Sample xml returned by my webservice:
<books>
<bookId>5</bookId>
<bookName>testBook</bookName>
</books>
I want to use book id as xml attribute for bookName:
<books>
<bookName id="5">testBook</bookName>
</books>
Any suggestion?
Based on how your java types are defined you can either annotate your classes with #XmlAttribute or may need to write your custom XmlAdapter
I'm trying to get the value of iWantToGetThis.jpg and put it into an <img> during my XSL transformation. This is how my xml is structures:
<article>
<info>
<mediaobject>
<imageobject>
<imagedata fileref='iWantToGetThis.jpg'>
Here's what I've come up with for the XSL:
<xsl:template name="user.header.content">
<xsl:stylesheet xmlns:d='http://docbook.org/ns/docbook'>
<img><xsl:attribute name="src">../icons/<xsl:value-of select='ancestor-or-self::d:article/info/mediaobject/imageobject/imagedata/#fileref' /></xsl:attribute></img>
</xsl:stylesheet>
</xsl:template>
The image is being added to the output, but the src attribute is set to "../icons/", so I'm assuming it's not finding the fileref attribute in the XML. This looks perfectly valid to me, so I'm not sure what I'm missing.
I am not sure how you can get anything back at all, because that does not look like a valid XSLT document (I would expect the error "Keyword xsl:stylesheet may not contain img.").
However, it may be you are just showing a fragment of the code. If this is the case, your issue may be that you have only specified the namespace for the article element, when you really need to specify it for all elements in your xpath. Try this
<xsl:value-of
select="ancestor-or-self::d:article/d:info/d:mediaobject/d:imageobject/d:imagedata/#fileref"/>
Another possible problem may be because you are using the 'ancestor-or-self' xpath axis to find the attribute. This would only work if your current context was already on the article element, or one of its descendants.
As a side note, you can simplify the code by making use of Attribute Value Templates here
<img src="../icons/{ancestor-or-self::d:article/d:info/d:mediaobject/d:imageobject/d:imagedata/#fileref}" />
I'm working on a little project for school. This project asks me to show that I'm capable of using various processing techniques of XML. Now, in my project I work with the Sedna database manager in which I keep user records and I would like to update some of these user records through XQuery (I use the PHP API to send the queries to the database through the PHP Api provided by the Sedna Developers team).
Imagine I have the following database content for the user records:
<?xml version="1.0" encoding="UTF-8"?>
<users>
<user id="admin" admin="true">
<email>admin#admin.com</email>
<password>123456789</password>
<firstname>The</firstname>
<lastname>Stig</lastname>
<gender>male</gender>
<subscriptions>
</subscriptions>
</user>
<user id="prosper" admin="false">
<email>prosper#localhost.com</email>
<password>123456789</password>
<firstname>Strange</firstname>
<lastname>Figure</lastname>
<gender>male</gender>
<subscriptions>
</subscriptions>
</user>
</users>
Now, I my intention here is to update, for example, prosper's userrecord. In this record I would like to, for example, change his firstname and email, but keeping the rest unchanged.
I have tried to use the following query, but after sending the query, it changes the document order of the userrecord for some reason I don't understand (I think it inserts the attributes nodes of the user record as childnodes).
This is the query I use to update the user:
UPDATE replace $user in doc("users")//user[#id="prosper"]
with
<user>{($user/#*)}
<email>strange.figure#localhost.com</email>
{($user/node()[password])}
<firstname>Familiar</firstname>
<lastname>Figure</lastname>
<gender>male</gender>
{($user/node()[subscriptions])}</user>
Now, the problem this query gives me, is that when I try to ask the user's information after the update, I rely on the same order of child nodes have from before the update, but this query changes the order.
Is there someone skilled enough to help me with this problem?
I thank you for your time.
Jan, if you want to get password node you should change your XPath (your current expression {($user/node()[password])} is not what you think):
{$user/password}
the same true for subscriptions:
{$user/subscriptions}
It can be written as one expression with predicate:
{$user/node()[local-name(.) = ('password', 'subscriptions')]}
I am trying to call the lists.asmx UpdateListItems() to delete a list item by unique id or guid. The following batch xml fails with "Invalid URL Parameter. The URL provided contains an invalid Command or Value. Please check the URL again".
<Batch OnError="Continue" ListVersion="1" ViewName="">
<Method ID="1" Cmd="Delete">
<Field Name="Guid">7be4a863ce-08de-4506-9c69-400749860e76</Field>
</Method>
</Batch>
In addition, I have tried with and without enclosing "{}", UrlEncoding, using UniqueId instead of Guid, prefixing the guid with "[id];#", etc. but to no avail.
Using the ID will work, but I would prefer using the Guid if possible:
<Batch OnError="Continue" ListVersion="1" ViewName="">
<Method ID="1" Cmd="Delete">
<Field Name="ID">29</Field>
</Method>
</Batch>
Anyone have any ideas, or is this not possible using the UniqueID or Guid?
From the documentation, they only give an example using ID... which leads me to believe it probably will not work with anything else.