--> This macro allows to reproduce your problem:
---
<command name="testIt">
<macro trace="true">
<sequence>
<command name="selectFile" parameter="openFile "/>
<get expression="relativize-uri(uri-or-file-name('%_'), '%{d}')"/>
<command name="alert" parameter="%_" />
</sequence>
</macro>
</command>
---
* If I open file ab.xml in XXE and execute testIt, this macro works as
expected.
* If I open file a'b.xml in XXE and execute testIt, this macro fails
with: cannot parse expression=...: unrecognized operator name.
* If I open file a"b.xml in XXE and execute testIt, this macro works as
expected.
--> It's easy to rewrite the macro in order to allow an apostrophe in an
filename:
---
<command name="testIt2">
<macro trace="true">
<sequence>
<command name="selectFile" parameter="openFile "/>
<get expression='relativize-uri(uri-or-file-name("%_"), "%{d}")'/>
<command name="alert" parameter="%_" />
</sequence>
</macro>
</command>
---
* If I open file ab.xml in XXE and execute testIt2, this macro works as
expected.
* If I open file a'b.xml in XXE and execute testIt2, this macro works as
expected.
* If I open file a"b.xml in XXE and execute testIt2, this macro fails
with: cannot parse expression=...: unrecognized operator name.
--> Now a little trick allows us to have something which works in all cases:
---
<command name="testIt3">
<macro trace="true">
<sequence>
<set variable="editedDocURL" expression="%{d}"
plainString="true" />
<command name="selectFile" parameter="openFile "/>
<get expression="relativize-uri(uri-or-file-name('%_'),
$editedDocURL)"/>
<command name="alert" parameter="%_" />
</sequence>
</macro>
</command>
---
* If I open file ab.xml in XXE and execute testIt3, this macro works as
expected.
* If I open file a'b.xml in XXE and execute testIt3, this macro works as
expected.
* If I open file a"b.xml in XXE and execute testIt3, this macro works as
expected.
On 10/23/2010 08:52 PM, Andy Black wrote:
> On 10/23/2010 1:24 AM, Hussein Shafie wrote:
>> On 10/22/2010 11:24 PM, Andy Black wrote:
>>> A user has a file name of
>>>
>>> Me'phaa.xml
>>>
>>> and was trying to run a custom macro I had made. The macro failed to work.
>>>
>>> When I debugged the macro and gave it the command
>>>
>>> <cfg:get expression="%{d}"/>
>> I guess that this is a simplification of what you want to do because, as
>> is, the above instruction does not make sense.
>>
>>
>>
>>> the result was:
>>>
>>> -->associatePublisherStylesheet:get: checking...
>>> cannot parse
>>> expression='file:/C:/Documents%20and%20Settings/Andy%20Black/My%20Documents/XLingPap/Users/SteveMarlett/Me'phaa.xml':
>>> bad character after :
>>> <--associatePublisherStylesheet:get: CANNOT EXECUTE
>>>
>>> There is no problem when the file name does not have the apostrophe in it.
>> With or without an apostrophe
>>
>> file:/C:/Documents%20and%20Settings/Andy%20Black/My%20Documents/XLingPap/Users/SteveMarlett/Me'phaa.xml
>>
>> is definitely not a valid XPath expression. There is nothing that can be
>> changed in that fact.
>>
>>
>>
>>> Is there a solution to this other than not using a single quote in the
>>> file name?
>>>
>> Probably, but I don't understand what is exactly the problem. Please
>> consider sending me a less simplified version of your macro.
>
> Sorry for not being clear.
>
> Here is the full macro, including some of my alerts to try and figure
> out what was happening. It uses a custom Java command
> (AssociatePublisherStylesheetCmd) that modifies the structure of the
> XML, but never got that far with a file name containing an apostrophe.
>
> <cfg:command name="associatePublisherStylesheet">
> <cfg:macro trace="true">
> <cfg:sequence>
> <cfg:choice>
> <cfg:pass>
> <cfg:command name="selectNode"
> parameter="ancestorOrSelf[implicitElement] lingPaper xlingpaper"/>
> </cfg:pass>
> <cfg:pass>
> <cfg:command name="selectNode"
> parameter="descendantOrSelf[implicitElement] lingPaper xlingpaper"/>
> </cfg:pass>
> </cfg:choice>
> <cfg:command name="selectFile" parameter="[Choose Publisher Style
> Sheet]openFile
> %{c}/../publisherstylesheets/SILInternationalPaperStylesheet.xml"/>
> <cfg:set variable="fileName" expression="%_" plainString="true"/>
> <cfg:get expression="$fileName"/>
> <cfg:command name="alert" parameter="After setting fileName: %_"/>
> <cfg:get expression="%{d}"/>
> <cfg:command name="alert" parameter="Percent d: %_"/>
> <cfg:get expression="$fileName"/>
> <cfg:get expression="relativize-uri(uri-or-file-name('%_'), '%{d}')"/>
> <cfg:set variable="uri" expression="%_" plainString="true"/>
> <cfg:command name="alert" parameter="Before invoking Java command"/>
> <cfg:get expression="concat($fileName, '|', $uri)"/>
> <cfg:command name="AssociatePublisherStylesheetCmd" parameter="%_"/>
> <cfg:set variable="result" expression="%_" plainString="true"/>
> <cfg:command name="alert" parameter="After invoking Java command"/>
> <cfg:choice>
> <cfg:sequence>
> <cfg:test expression="string-length($result) > 0"/>
> <cfg:get expression="$result"/>
> <cfg:command name="alert" parameter="%_"/>
> </cfg:sequence>
> <cfg:sequence>
> <cfg:command name="XXE.save" parameter="[ifNeeded]"/>
> <cfg:command name="XXE.open" parameter="%D"/>
> </cfg:sequence>
> </cfg:choice>
> </cfg:sequence>
> </cfg:macro>
> </cfg:command>
>
--
XMLmind XML Editor Support List
[email protected]
http://www.xmlmind.com/mailman/listinfo/xmleditor-support