Jump to content

document('') workaround MSXML 6 & MS-Word transform issue.


juanmf

Recommended Posts

Hi, I've been trying to find a way to force MSWord to save a word 2003 XML document, applying a XSLT stylesheet. But whenever I use special chars it triggers a document('') function that breaks the process with the following error:

Operation aborted: AllowDocumentFunction constraint violated

I've seen lost of posts recommending something like:

xsl.setProperty('AllowDocumentFunction', true);

But I obviously cant use this trick in a Word "save as with transform" context. Also tried to put an embedded script :

<msxsl:script language="JScript" implements-prefix="my">Document.setProperty("AllowDocumentFunction", true);   </msxsl:script>

but it was silly to think that one could hack it from inside the stylesheet...

[color=#333333][font=Arial][size=3]Security settings do not allow the execution of script code within this stylesheet[/size][/font][/color]

Which led me to this post: http://forums.ni.com...de/td-p/1003028 I tried setting the XSLSecurityLevel for Word in the registry with no luck. So the last option I see is a fix in the styesheet that's be able to avoid the use of document():

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"				xmlns:my="dummy.namespace"				version="1.0">	<my:recoding-table font="Symbol">	  <my:char code="!" value="21" altvalue="F021" entity="!"/> <!--EXCLAMATION MARK-->	  <my:char code=""" value="22" altvalue="F022" entity="∀"/> <!--FOR ALL-->......	</my:recoding-table>......	<xsl:if test="string-length($string)">   <xsl:value-of select="substring(document('')//my:recoding-table[@font=$font-family]/my:char[substring(@code, 1, 1)=substring($string, 1, 1)]/@entity, 1, 1)"/>	</xsl:template>...

See how the stylesheet opens '' (this sheet) to make a XPATH query in its own my:recoding-table node. Question: How can I put my:recoding-table in a variable and query in it, or HOW can I get the same result without using document('')? Thanks!

Edited by juanmf
Link to comment
Share on other sites

Assuming you target MSXML 6 in Office you could try to define the mapping table as a global parameter and then use the node-set extension function that MSXML supports to have a node set you can apply XPath on:

<xsl:param name="my-table-rtf">	    <my:recoding-table font="Symbol">		  <my:char code="!" value="21" altvalue="F021" entity="!"/> <!--EXCLAMATION MARK-->		  <my:char code=""" value="22" altvalue="F022" entity="∀"/> <!--FOR ALL-->......	    </my:recoding-table></xsl:param><xsl:variable name="my-table" select="msxsl:node-set($my-table-rtf)" xmlns:msxsl="urn:schemas-microsoft-com:xslt"/>...<xsl:value-of select="substring($my-table/my:recoding-table[@font=$font-family]/my:char[substring(@code, 1, 1)=substring($string, 1, 1)]/@entity, 1, 1)"/>

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...