Ureader.com  
Microsoft software help and Community
   home   |   control panel login   |   archive   |  
 
XML
data.xmlanalysis
mappoint.webservice
msf
msxml-webrelease
netmyservices.sdk
passport.sdk
soap
soapsdk
uddi.general
uddi.programming
uddi.specification
xml
xmlsqlwebrelease
xsl
  
 
date: Tue, 20 May 2008 05:55:06 -0600,    group: microsoft.public.xsl        back       


How do I prevent the tranform from moving namespaces?   
PROBLEM:

I am trying to get perform a transform of an XML document into a WordML 
document.

There's one hangup I'm having, preventing the creation of a valid WordML 
doc. WordML is apparently VERY picky about what element the namespace 
declaration appears on, and XSLT is rather manipulative about where it 
places them--disregarding where I have them in the transform.

So for example, I have:

<xsl:template name="foo">
  <pkg:part pkg:name="/docProps/custom.xml" 
pkg:contentType="application/vnd.openxmlformats-officedocument.custom-properties+xml" 
pkg:padding="256">
   <pkg:xmlData>
    <Properties 
xmlns="http://schemas.openxmlformats.org/officeDocument/2006/custom-properties" 
xmlns:vt="http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes">
     <property fmtid="{{D5CDD505-2E9C-101B-9397-08002B2CF9AE}}" pid="2" 
name="Customer">
      <vt:lpwstr>
       <xsl:value-of select="/my:myFields/my:Project"/>
      </vt:lpwstr>
     </property>
    </Properties>
   </pkg:xmlData>
  </pkg:part>
</xsl:template>


But what I get out of it is:

 <pkg:part pkg:name="/docProps/custom.xml" 
pkg:contentType="application/vnd.openxmlformats-officedocument.custom-properties+xml" 
pkg:padding="256">
  <pkg:xmlData>
   <Properties 
xmlns="http://schemas.openxmlformats.org/officeDocument/2006/custom-properties">
    <property fmtid="{D5CDD505-2E9C-101B-9397-08002B2CF9AE}" pid="2" 
name="Customer" xmlns="">
     <vt:lpwstr 
xmlns:vt="http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes">Exchange 
2007 Migration</vt:lpwstr>
    </property>
   </Properties>
  </pkg:xmlData>
 </pkg:part>


Note that xmlns:vt has been moved duing the transform from the Properties 
element to the vt:lpwstr element. While in theory, this should not be an 
issue (and isn't through the rest of the document with other namespaces 
where this occured), this particular namespace is causing the resulting 
WordML to become invalid. Word is expecting and demanding that it be placed 
onthe Properties element in order for the document to be valid.

I've done a diff of all other changes, and they all work fine except for the 
case of this one namespace. Why it makes a difference I don't know, but it 
does.


QUESTION:

So somehow I need to force that namespace to appear on the Properties 
element instead of being moved down to the elements that uses the 
namespaces.

How do I do this without having to do something completely obnoxious like 
convert 6000 lines into tons more by using <xsl:element/> and 
<xsl:attribute/> everywhere?

-- 
Greg Collins
Microsoft MVP
Visit Braintrove at http://www.braintrove.com
Visit InfoPathDev at http://www.infopathdev.com
date: Tue, 20 May 2008 05:55:06 -0600   author:   Greg Collins gcollins_at_msn_dot_com

Re: How do I prevent the tranform from moving namespaces?   
Looks like I found a way -- kind of convoluted, but it works: Use <xsl:text 
disable-output-escaping="yes"><![CDATA[ . . . ]]></xsl:text>

<xsl:template name="foo">
<xsl:text disable-output-escaping="yes"><![CDATA[
  <pkg:part pkg:name="/docProps/custom.xml" 
pkg:contentType="application/vnd.openxmlformats-officedocument.custom-properties+xml" 
pkg:padding="256">
   <pkg:xmlData>
    <Properties 
xmlns="http://schemas.openxmlformats.org/officeDocument/2006/custom-properties" 
xmlns:vt="http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes">
     <property fmtid="{{D5CDD505-2E9C-101B-9397-08002B2CF9AE}}" pid="2" 
name="Customer">
      <vt:lpwstr>]]></xsl:text>
       <xsl:value-of select="/my:myFields/my:Project"/>
      <xsl:text disable-output-escaping="yes"><![CDATA[</vt:lpwstr>
     </property>
    </Properties>
   </pkg:xmlData>
  </pkg:part>
]]></xsl:text>
</xsl:template>
-- 
Greg Collins
Microsoft MVP
Visit Braintrove at http://www.braintrove.com
Visit InfoPathDev at http://www.infopathdev.com
date: Tue, 20 May 2008 06:18:51 -0600   author:   Greg Collins gcollins_at_msn_dot_com

Re: How do I prevent the tranform from moving namespaces?   
Greg Collins wrote:

> So for example, I have:
> 
> <xsl:template name="foo">
>  <pkg:part pkg:name="/docProps/custom.xml" 
> pkg:contentType="application/vnd.openxmlformats-officedocument.custom-properties+xml" 
> pkg:padding="256">
>   <pkg:xmlData>
>    <Properties 
> xmlns="http://schemas.openxmlformats.org/officeDocument/2006/custom-properties" 
> xmlns:vt="http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes"> 
> 
>     <property fmtid="{{D5CDD505-2E9C-101B-9397-08002B2CF9AE}}" pid="2" 
> name="Customer">
>      <vt:lpwstr>
>       <xsl:value-of select="/my:myFields/my:Project"/>
>      </vt:lpwstr>
>     </property>
>    </Properties>
>   </pkg:xmlData>
>  </pkg:part>
> </xsl:template>
> 
> 
> But what I get out of it is:
> 
> <pkg:part pkg:name="/docProps/custom.xml" 
> pkg:contentType="application/vnd.openxmlformats-officedocument.custom-properties+xml" 
> pkg:padding="256">
>  <pkg:xmlData>
>   <Properties 
> xmlns="http://schemas.openxmlformats.org/officeDocument/2006/custom-properties"> 
> 
>    <property fmtid="{D5CDD505-2E9C-101B-9397-08002B2CF9AE}" pid="2" 
> name="Customer" xmlns="">
                   ^^^^^^^^

I kind of doubt that the above template creates this output but if it 
does then there is a bug in the XSLT processor or XML parser you use.
But an xmlns="" usually indicates that there is a problem in the 
stylesheet and not with the XSLT processor.
Can you post a minimal but complete XML input and XSLT stylesheet and 
tell us which XSLT processor you use?



-- 

	Martin Honnen --- MVP XML
	http://JavaScript.FAQTs.com/
date: Tue, 20 May 2008 14:22:25 +0200   author:   Martin Honnen

Re: How do I prevent the tranform from moving namespaces?   
One change is that now that the XML is in a CDATA block, I don't need to 
escape the curly braces in the fmtid attribute, so they should be:

fmtid="{D5CDD505-2E9C-101B-9397-08002B2CF9AE}"

instead of:

fmtid="{{D5CDD505-2E9C-101B-9397-08002B2CF9AE}}"

Before the CDATA block, I needed to escpape them to prevent them from being 
identified as an Attribute Value Template.

-- 
Greg Collins
Microsoft MVP
Visit Braintrove at http://www.braintrove.com
Visit InfoPathDev at http://www.infopathdev.com
date: Tue, 20 May 2008 06:24:35 -0600   author:   Greg Collins gcollins_at_msn_dot_com

Re: How do I prevent the tranform from moving namespaces?   
xmlns="" is perfectly legal. It is a default namespace. You'll also notice 
that the xmlns="" was not generated per-se... it was copied from the 
original XML in the template. This is XML generated from Word when saving 
the file as WordML.

I am using the C# .NET 2.0 Translate() functionality.

-- 
Greg Collins
Microsoft MVP
Visit Braintrove at http://www.braintrove.com
Visit InfoPathDev at http://www.infopathdev.com
date: Tue, 20 May 2008 09:10:10 -0600   author:   Greg Collins gcollins_at_msn_dot_com

Re: How do I prevent the tranform from moving namespaces?   
Greg Collins wrote:
> xmlns="" is perfectly legal. It is a default namespace. You'll also 
> notice that the xmlns="" was not generated per-se... it was copied from 
> the original XML in the template. This is XML generated from Word when 
> saving the file as WordML.

I know xmlns="" is legal but there is nothing in the template you posted 
that would result in xmlns="". You will need to show your input and a 
minimal but complete stylesheet.

> I am using the C# .NET 2.0 Translate() functionality.

.NET has two XSLT processors, XslTransform and XslCompiledTranform. 
Which one do you use?

-- 

	Martin Honnen --- MVP XML
	http://JavaScript.FAQTs.com/
date: Tue, 20 May 2008 17:24:23 +0200   author:   Martin Honnen

Re: How do I prevent the tranform from moving namespaces?   
XslCompiledTransform

If you look at the original post, you'll see that the default xmns was 
defined on the Properties element right there inside the xsl:template and 
would therefore be expected to show in the resulting output.

Keep in mind that in a particular named template, I'm just dumping out 
(regurgitating) the bulk of the WordML XML structure. There's two other 
named templates that handle the core properties (with lots of values being 
dropped in place) and the main document body (with several repeating 
structures and values). Most of the WordML is just static and just needs to 
be dumped out as is.

-- 
Greg Collins
Microsoft MVP
Visit Braintrove at http://www.braintrove.com
Visit InfoPathDev at http://www.infopathdev.com
date: Tue, 20 May 2008 15:17:31 -0600   author:   Greg Collins gcollins_at_msn_dot_com

Google
 
Web ureader.com


    COPYRIGHT 2007, YARDI TECHNOLOGY LIMITED, ALL RIGHT RESERVE  |   contact us