XML Editor
Sign up for a WebBoard account Sign Up Keyword Search Search More Options... Options
Chat Rooms Chat Help Help News News Log in to WebBoard Log in Not Logged in
Show tree view Topic
Go to previous topicPrev TopicGo to next topicNext Topic
Postnext
Shane GarringerSubject: How to map a recursive node?
Author: Shane Garringer
Date: 17 Dec 2005 12:05 PM
I am trying to map MS Word 2003 schema to the same targer schema. The reason for this is to translate one MS Word xml file to the same format without a couple of the nodes. The problem I am running into is that the 'frameSet node is recursive. I don't know how to map this, as dragging a line from one node to the other is an endless loop with the recursion. Any help with this would greatly be appreciated. I have attached the wordnet.xsd and its import xsd's

Thanks,

Shane


Unknownwordnet.xsd
word 2003 scema

Unknownaml.xsd
import xsd

Unknownoffice.xsd
imort xsd

Unknownvml.xsd
import xsd

Unknownw10.xsd
import xsd

Unknownwordnetaux.xsd
import xsd

Unknownxsdlib.xsd
import xsd

Postnext
Minollo I.Subject: How to map a recursive node?
Author: Minollo I.
Date: 18 Dec 2005 12:16 AM
Would a copy of the recursive node work? In that case in mapper just drag&drop the node using the right button of the mouse and choose "Create copy link".

Minollo

Postnext
Shane GarringerSubject: How to map a recursive node?
Author: Shane Garringer
Date: 18 Dec 2005 07:17 PM
I honestly don't know if that would work. i don't have enough experience with xml or xslt to know exactly what I need to do. All I know is, I need to create an XSLT document that I can use to take one word 2003 xml document and translate it to another word 2003 xml document. Their are only a couple elements I don't want to get copied over to the new document. Will the copy you stated do that?

Postnext
Minollo I.Subject: How to map a recursive node?
Author: Minollo I.
Date: 18 Dec 2005 09:37 PM
Actually, as you posted in "XQuery Help and Discussion" I was assuming that you were trying to solve your problem using XQuery... And I was suggesting that you could use the copy link (that is also available in XSLT, implemented as a xsl:copy-of) to take care of the recursive node - assuming that all children of the recursive node should be copied.

Anyway, another way to do what you are trying to do using XSLT would be to create a <xsl:template match="*"> that matches on all elements, and then inside such template copy the element and attributes if it's an element that should be copied, and move on apply templates on children.

Something like this:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="*">
<xsl:if test="name() != 'badElem1' and name() != 'badElem2'">
<xsl:element name="{name()}">
<xsl:for-each select="@*">
<xsl:attribute name="{name()}">
<xsl:value-of select="."/>
</xsl:attribute>
</xsl:for-each>
<xsl:apply-templates/>
</xsl:element>
</xsl:if>
</xsl:template>
</xsl:stylesheet>

Hope this helps,
Minollo

Postnext
Shane GarringerSubject: How to map a recursive node?
Author: Shane Garringer
Date: 18 Dec 2005 10:59 PM
Thanks for the help, but I still am not getting what I need. i sued your code above, and it gets the attributes of the root level, but I cant figure out how to move on to the child elements.

code:

<?xml version='1.0' ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:w="http://schemas.microsoft.com/office/word/2003/wordml" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:w10="urn:schemas-microsoft-com:office:word" xmlns:sl="http://schemas.microsoft.com/schemaLibrary/2003/core" xmlns:aml="http://schemas.microsoft.com/aml/2001/core" xmlns:wx="http://schemas.microsoft.com/office/word/2003/auxHint" xmlns:o="urn:schemas-microsoft-com:office:office">
<xsl:template match="/">
<xsl:apply-templates select=""/>
</xsl:template>
<xsl:template match="*">
<xsl:if test="name() != w:docOleData"> //don't copy this element
<xsl:element name="{name()}">
<xsl:for-each select="@*">
<xsl:attribute name="{name()}">
<xsl:value-of select="."/>
</xsl:attribute>
</xsl:for-each>
<xsl:apply-templates/>
</xsl:element>
</xsl:if>
</xsl:template>
</xsl:stylesheet>

results:

<w:wordDocument xmlns:w="http://schemas.microsoft.com/office/word/2003/wordml" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:w10="urn:schemas-microsoft-com:office:word" xmlns:sl="http://schemas.microsoft.com/schemaLibrary/2003/core" xmlns:aml="http://schemas.microsoft.com/aml/2001/core" xmlns:wx="http://schemas.microsoft.com/office/word/2003/auxHint" xmlns:o="urn:schemas-microsoft-com:office:office" w:macrosPresent="yes" w:embeddedObjPresent="yes" w:ocxPresent="no" xml:space="preserve"/>

Postnext
Minollo I.Subject: How to map a recursive node?
Author: Minollo I.
Date: 18 Dec 2005 11:22 PM
Actually if the code you are running is exactly what you posted here, I'm surprised you get any output at all (not the missing single quotes around w:docOleData! And the "//" comment, is not a comment... it will copied verbatim to the output)

Try using this; it works fine for me:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:w="http://schemas.microsoft.com/office/word/2003/wordml" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:w10="urn:schemas-microsoft-com:office:word"
xmlns:sl="http://schemas.microsoft.com/schemaLibrary/2003/core" xmlns:aml="http://schemas.microsoft.com/aml/2001/core" xmlns:wx="http://schemas.microsoft.com/office/word/2003/auxHint" xmlns:o="urn:schemas-microsoft-com:office:office">
<xsl:template match="/">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="*">
<xsl:if test="name() != 'w:docOleData'"> <!--don't copy this element-->
<xsl:element name="{name()}">
<xsl:for-each select="@*">
<xsl:attribute name="{name()}">
<xsl:value-of select="."/>
</xsl:attribute>
</xsl:for-each>
<xsl:apply-templates/>
</xsl:element>
</xsl:if>
</xsl:template>
</xsl:stylesheet>

Postnext
Shane GarringerSubject: How to map a recursive node?
Author: Shane Garringer
Date: 18 Dec 2005 11:35 PM
Wooo Hooo, that works magnificently!! Now, one more question. the first attributes in the wordDocument. (i.e macrosPresent) I would like to just set them to no. Can this be done using the code you gave me? I know you can just right click the element and set the text for this, but when I do that after i have pasted your code in there, it screams at me about 'w' not being mapped to any URI??

Postnext
Minollo I.Subject: How to map a recursive node?
Author: Minollo I.
Date: 18 Dec 2005 11:44 PM
The code I sent you uses a logic completely different from what mapper understands. You won't be able to do much with mapper starting from it.

If you want to change values to attributes based on some logic, you can do something like this:

<xsl:template match="*">
<xsl:variable name="elementName">
<xsl:value-of select="name()"/>
</xsl:variable>
<xsl:if test="$elementName != 'w:docOleData'">
<!--don't copy this element-->
<xsl:element name="{$elementName}">
<xsl:for-each select="@*">
<xsl:attribute name="{name()}">
<xsl:choose>
<xsl:when test="name() = 'w:macrosPresent' and $elementName = 'w:wordDocument'">
<xsl:value-of select="'no'"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="."/>
</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
</xsl:for-each>
<xsl:apply-templates/>
</xsl:element>
</xsl:if>
</xsl:template>

Posttop
Shane GarringerSubject: How to map a recursive node?
Author: Shane Garringer
Date: 18 Dec 2005 11:51 PM
beautiful!! just beautiful!! thanks you!!

 
Go to previous topicPrev TopicGo to next topicNext Topic
Download A Free Trial of Stylus Studio 6 XML Professional Edition Today! Powered by Stylus Studio, the world's leading XML IDE for XML, XSLT, XQuery, XML Schema, DTD, XPath, WSDL, XHTML, SQL/XML, and XML Mapping!  
go

Log In Options

Site Map | Privacy Policy | Terms of Use | Trademarks
Stylus Scoop XML Newsletter:
W3C Member
Stylus Studio® and DataDirect XQuery ™are from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2016 All Rights Reserved.