XSLT Tools and InDesign script -- Remove "

hi There,

Working on this code, i’m can’t seem to figure it out:
It returns {“XX, XX, XX, XX”} instead of {XX, XX, XX, XX}
when the " " are present InDesign can’t make a color

Can somebody tell me why and HOWTO remove them?

Thanks,
Steven

note: install http://www.latenightsw.com/freeware/XSLTTools/index.html


set theXML to "<?xml version="1.0"?>
<swatches>
  <data value="00, 00, 100, 00" name="Color 1"/>
  <data value="00, 100, 0, 0" name="Color 2"/>
</swatches>"

set valueItem to extract from XML theXML matching "swatches/data" expression {"@value"} as string
set nameItem to extract from XML theXML matching "swatches/data" expression {"@name"} as string

set anItem to text items of valueItem
set AppleScript's text item delimiters to ""
set theCounter to count of anItem

tell application "InDesign CS"
	set theDoc to make document
	set theDoc to document 1
	tell theDoc
		try
			repeat with i from 1 to theCounter
				set a to item i of valueItem as list
				set b to item i of nameItem
				set newColor to make color with properties {model:spot, space:CMYK, color value:a, name:b}
			end repeat
		on error number -2710 -- Can't make color
			beep			
			--close theDoc saving no
		end try
	end tell
end tell

The value you’re extracting into variable a is a list containing one item, a string, ie. {“00, 00, 100, 00”}. What you want is a list containing four numbers (presumably - I don’t know the InDesign dictionary).

Rather than the statement


         set a to item i of valueItem as list

you need something like


    set a to {}
    set curval to words of item i of valueItem
    repeat with i from 1 to number of items in curval
    set a to a & item i of curval as number
    end repeat

hi,

Thanks that helped a lot :slight_smile:
Replaced

 set a to item i of valueItem as list 

with


set curval to words of item i of valueItem
repeat with i from 1 to number of items in curval
set {c, y, m, k} to {item 1 of curval as number, item 2 of curval as number, item 3 of curval as number, item 4 of curval as number}
end repeat

the ID tag looks like this color value:{c, y, m, k}

Not really good scripting i presume, but it works.
Any suggestions for a better scripting?

Steven

I don’t think you need the repeat loop, since the set statement picks up all the values from curval at one time. It doesn’t hurt, it just does the same work four times.

I hadn’t realized that you could set all the values at once in Applescript. That’s pretty cool.

I removed the repeat lines, indeed, everything is still working.
Thanks,

Steven