xsl-list
[Top] [All Lists]

RE: WordML to XML

2005-02-12 03:46:40
     Hi,
        I too have been trying to figure out how this could be done when you 
got there first. I  knew some kind of look-ahead would be needed as in the use 
of the following-sibling but didn't     know the exact means. Does the use of 
priority have any specific significance and also the use of the [1]( first 
child? ) everywhere. 

  Cheers,
  Omprakash.V
 
                




        
       

-----Original Message-----
From: Joris Gillis [mailto:roac(_at_)pandora(_dot_)be]
Sent: Saturday, February 12, 2005 3:49 PM
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: Re: [xsl] WordML to XML


Tempore 03:14:57, die 02/12/2005 AD, hinc in  
xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com scripsit Vasu Nanjangud  
<vasdeep(_at_)yahoo(_dot_)com>:

Joris, et al...

My requirement is specifically to convert wordML to
xml. i.e. strip off the "wordML" specific tags, but
retain the "formatting instructions".


When you apply this template to your WordML doc:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";  
version="1.0"  
xmlns:w="http://schemas.microsoft.com/office/word/2003/wordml";  
exclude-result-prefixes="w">
   <xsl:output method="xml" version="1.0" encoding="UTF-8"
indent="yes"/>

<xsl:template match="w:wordDocument">
        <vasuarticletag>
                <xsl:apply-templates select=".//w:body"/>
        </vasuarticletag>
</xsl:template>

<xsl:template match="w:r ">
        <xsl:apply-templates select="(w:rPr|w:t)[1]"  mode="styling"/>
</xsl:template>

<xsl:template match="w:rPr"  mode="styling">
        <xsl:apply-templates select="*[1]" mode="styling"/>
</xsl:template>

<xsl:template match="w:u|w:b|w:i" priority="5"  mode="styling">
        <xsl:element name="{local-name()}">
                <xsl:apply-templates 
select="(following-sibling::*|../../w:t)[1]"   
mode="styling"/>
        </xsl:element>
</xsl:template>

<xsl:template match="w:rPr/*"  mode="styling">
        <xsl:apply-templates select="(following-sibling::*|../../w:t)[1]"   
mode="styling"/>
</xsl:template>

<xsl:template match="w:t"  mode="styling"><xsl:value-of  
select="."/></xsl:template>

</xsl:stylesheet>



you will get this output:

<vasuarticletag>
<b>
    <i>
      <u>
          I have bold, italics and underscore
      </u>
    </i>
</b>
</vasuarticletag>


(I added modes, so the algorithm will not interfere with other templates  
you might be using.)


So, I need help in writing an xslt which will
1. traverse through every "w:r" block.
done.

2. Look for "w:rPr" tags with "w:i", "w:b" , "w:u"
children.
possible, but not necessary.
3. If they exist, output <i>, <b>, <u> tags, then
output the contents of the corresponding "w:t" block
and then close the <i>, <b>, <u> tags.
This is not the way XSLT works. In XSLT you construct elements, which are  
added to the result tree. When the XSLT processing is done, a serializer  
outputs these elements as tags.
In other words, you cannot "open a tag" nor "close a tag" in XSLT. (unless  
your messing with it as if it was character data, but don't do that)

While step 3 of your the algorithm, can't be used in XSLT. The templates  
in my stylesheet will give output exactly as if they were following step 3.


regards,
-- 
Joris Gillis (http://www.ticalc.org/cgi-bin/acct-view.cgi?userid=38041)
Gaudiam omnibus traderat W3C, nec vana fides

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--





--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



<Prev in Thread] Current Thread [Next in Thread>