Page 1 of 2

Replace comma with a dot

Posted: Fri Oct 30, 2020 3:14 pm
by schmitzdp
Hello,

I would like to replace commas by dots in the "productsize" node to get this result: "102.6 Small x 122.6 Big (CM)"

Below, my xml example:

Code: Select all

<order>
	<items>
		<productsize>102,6 Small x 122,6 Big (CM)</productsize>
	</items>
</order>
Do you know the function to do this? Thank you ;)

Re: Replace comma with a dot

Posted: Fri Oct 30, 2020 5:38 pm
by freddyp
This is something you can do directly in the XPath with which you get the info from the XML using an XPath function:
Screen Shot 2020-10-30 at 15.35.00.png
Screen Shot 2020-10-30 at 15.35.00.png (76.96 KiB) Viewed 19097 times
The XPath expression is perhaps not so readable in the image:

Code: Select all

translate(//productsize,',','.')

Re: Replace comma with a dot

Posted: Tue Nov 03, 2020 9:24 am
by schmitzdp
It's even simpler and it works perfectly. Thank you :D

Re: Replace comma with a dot

Posted: Wed Feb 10, 2021 1:48 pm
by schmitzdp
Hello,

is there a similar expression that can modify for example a white space by 3 characters?

Code: Select all

translate(//url,' ','%20')

Re: Replace comma with a dot

Posted: Thu Feb 11, 2021 10:10 am
by freddyp
There is not a similar expression, it is the same expression. The example you give replaces all spaces by %20 in //url.

Re: Replace comma with a dot

Posted: Thu Feb 11, 2021 7:20 pm
by schmitzdp
freddyp wrote: Thu Feb 11, 2021 10:10 am There is not a similar expression, it is the same expression. The example you give replaces all spaces by %20 in //url.
No, I tested before posting and all spaces is replaced only by % in //url.

Re: Replace comma with a dot

Posted: Fri Feb 12, 2021 9:55 am
by freddyp
Indeed, my mistake, translate only replaces by the first character. Who ever came up with that idea? There is a replace function but that is only available in XPath 2.0 and Switch uses 1.0.

Before reverting to XSL or scripting I would try this app: https://www.enfocus.com/en/appstore/pro ... ng-replace
The fact that you want to replace a space and not a string like zdhr#$22 will probably make it tricky, but the app has support for regular expressions, so it is worth trying.

Before even doing that, where do you want to use the string? If you use the information in the Parameters property of "HTTP request" for example it will be encoded automatically and spaces will become %20 etc.

And before even doing that, if it is a complete URL that is in your XML, go pull the ears of the person who wrote that URL there without encoding it as such! And do not let go until the problem is fixed at the source.

Re: Replace comma with a dot

Posted: Sun Feb 14, 2021 6:00 pm
by schmitzdp
Thank you for this complete answer. ;)

I was trying to write an url with the name of my file as a variable.

I simply used the "Rename Job" application before writing my url (with Job.NameProper).

I was complicating my life :lol:

Re: Replace comma with a dot

Posted: Mon Mar 01, 2021 5:48 pm
by bleuprocess
There is an app for that!
https://www.enfocus.com/en/appstore/pro ... me-cleaner

If anything is missing, just shout, I actually did write that one ;)

Re: Replace comma with a dot

Posted: Tue Aug 24, 2021 11:48 am
by schmitzdp
freddyp wrote: Fri Feb 12, 2021 9:55 am Before even doing that, where do you want to use the string? If you use the information in the Parameters property of "HTTP request" for example it will be encoded automatically and spaces will become %20 etc.
Can you give me an example of how to configure the HTTP request application to download a file whose url is stored in a metadata?

I can't seem to set it up correctly for this to work.

Thanks for your help.

Re: Replace comma with a dot

Posted: Tue Aug 24, 2021 12:10 pm
by jan_suhr
You use the GET as request type and in the URL you set the variable from the metadata.

Lik this:

Code: Select all

http://10.0.1.10/switch_upload/uploads/[Metadata.Text:Path="//Parameter/@Name",Dataset="uploaded",Model="XML"]
Where Parameter/@Name is the filename to get in the server URL-path.

Re: Replace comma with a dot

Posted: Tue Aug 24, 2021 12:15 pm
by schmitzdp
jan_suhr wrote: Tue Aug 24, 2021 12:10 pm You use the GET as request type and in the URL you set the variable from the metadata.

Lik this:

Code: Select all

http://10.0.1.10/switch_upload/uploads/[Metadata.Text:Path="//Parameter/@Name",Dataset="uploaded",Model="XML"]
Where Parameter/@Name is the filename to get in the server URL-path.
This works fine but if the file has a space in it, I get the error below:

Code: Select all

Request completion status: Failed; status code: 400; status description: Bad Request; last error: HTTP protocol error. 400 Bad Request.
The application does not convert the space to "%20"

Re: Replace comma with a dot

Posted: Tue Aug 24, 2021 12:20 pm
by jan_suhr
Then you have to use this app https://www.enfocus.com/en/appstore/pro ... ng-replace

It will let you create a new variable that has replaced the spaces with %20

Re: Replace comma with a dot

Posted: Tue Aug 24, 2021 1:20 pm
by schmitzdp
jan_suhr wrote: Tue Aug 24, 2021 12:20 pm Then you have to use this app https://www.enfocus.com/en/appstore/pro ... ng-replace

It will let you create a new variable that has replaced the spaces with %20
Is it possible to target only the tag containing the url?
In my tests, the function replaces all spaces in all tags.

Re: Replace comma with a dot

Posted: Tue Aug 24, 2021 1:27 pm
by jan_suhr
You should be able to specify the variable as the string to replace the spaces in.