Replace comma with a dot

schmitzdp
Member
Posts: 28
Joined: Thu Aug 06, 2020 1:36 pm

Replace comma with a dot

Post by schmitzdp » Fri Oct 30, 2020 3:14 pm

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 ;)

freddyp
Advanced member
Posts: 635
Joined: Thu Feb 09, 2012 3:53 pm

Re: Replace comma with a dot

Post by freddyp » Fri Oct 30, 2020 5:38 pm

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 3888 times
The XPath expression is perhaps not so readable in the image:

Code: Select all

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

schmitzdp
Member
Posts: 28
Joined: Thu Aug 06, 2020 1:36 pm

Re: Replace comma with a dot

Post by schmitzdp » Tue Nov 03, 2020 9:24 am

It's even simpler and it works perfectly. Thank you :D

schmitzdp
Member
Posts: 28
Joined: Thu Aug 06, 2020 1:36 pm

Re: Replace comma with a dot

Post by schmitzdp » Wed Feb 10, 2021 1:48 pm

Hello,

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

Code: Select all

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

freddyp
Advanced member
Posts: 635
Joined: Thu Feb 09, 2012 3:53 pm

Re: Replace comma with a dot

Post by freddyp » 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.

schmitzdp
Member
Posts: 28
Joined: Thu Aug 06, 2020 1:36 pm

Re: Replace comma with a dot

Post by schmitzdp » Thu Feb 11, 2021 7:20 pm

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.

freddyp
Advanced member
Posts: 635
Joined: Thu Feb 09, 2012 3:53 pm

Re: Replace comma with a dot

Post by freddyp » Fri Feb 12, 2021 9:55 am

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.

schmitzdp
Member
Posts: 28
Joined: Thu Aug 06, 2020 1:36 pm

Re: Replace comma with a dot

Post by schmitzdp » Sun Feb 14, 2021 6:00 pm

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:

bleuprocess
Newbie
Posts: 2
Joined: Wed Nov 23, 2011 10:43 am
Contact:

Re: Replace comma with a dot

Post by bleuprocess » Mon Mar 01, 2021 5:48 pm

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 ;)

schmitzdp
Member
Posts: 28
Joined: Thu Aug 06, 2020 1:36 pm

Re: Replace comma with a dot

Post by schmitzdp » Tue Aug 24, 2021 11:48 am

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.

jan_suhr
Advanced member
Posts: 446
Joined: Fri Nov 04, 2011 1:12 pm
Location: Nyköping, Sweden

Re: Replace comma with a dot

Post by jan_suhr » 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.
Jan Suhr
Color Consult AB
Sweden
=============
Check out my apps

schmitzdp
Member
Posts: 28
Joined: Thu Aug 06, 2020 1:36 pm

Re: Replace comma with a dot

Post by schmitzdp » Tue Aug 24, 2021 12:15 pm

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"

jan_suhr
Advanced member
Posts: 446
Joined: Fri Nov 04, 2011 1:12 pm
Location: Nyköping, Sweden

Re: Replace comma with a dot

Post by jan_suhr » 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
Jan Suhr
Color Consult AB
Sweden
=============
Check out my apps

schmitzdp
Member
Posts: 28
Joined: Thu Aug 06, 2020 1:36 pm

Re: Replace comma with a dot

Post by schmitzdp » Tue Aug 24, 2021 1:20 pm

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.

jan_suhr
Advanced member
Posts: 446
Joined: Fri Nov 04, 2011 1:12 pm
Location: Nyköping, Sweden

Re: Replace comma with a dot

Post by jan_suhr » Tue Aug 24, 2021 1:27 pm

You should be able to specify the variable as the string to replace the spaces in.
Jan Suhr
Color Consult AB
Sweden
=============
Check out my apps

Post Reply