[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Fwd: Re: [xsl] WordML to XML


Subject: Fwd: Re: [xsl] WordML to XML
From: Vasu Nanjangud <vasdeep@xxxxxxxxx>
Date: Sat, 12 Feb 2005 23:48:43 -0800 (PST)

Joris,
Thanks a lot! That works like a charm :-).
Can I also handle "w:listPr" tags which are a little
complicated implementation for "list Items - <OL>
<LI>.."...

Thanks for your time. 

Regards,
Vasu


--- Vasu Nanjangud <vasdeep@xxxxxxxxx> wrote:

> Date: Fri, 11 Feb 2005 18:14:57 -0800 (PST)
> From: Vasu Nanjangud <vasdeep@xxxxxxxxx>
> Subject: Re: [xsl] WordML to XML
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> 
> Joris, et al...
> 

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)





		
__________________________________ 
Do you Yahoo!? 
Read only the mail you want - Yahoo! Mail SpamGuard. 
http://promotions.yahoo.com/new_mail 


Current Thread
Keywords