Page 1 of 1

Newbie: XSLT variables?

Posted: Mon Sep 29, 2008 2:58 pm
by eivindan
Hi,

I'm new to XSLT and have a problem with using data from a template in another one.

The input (word 2007):

Code: Select all

<w:p>
<w:pPr>
<w:pStyle w:val="MyStyle"/>
</w:pPr>
<w:r>
<w:rPr>
<w:b/>
</w:rPr>
<w:t>Some bold text</w:t>
</w:r>
</w:p>
Output should be (indesign tagged text):

Code: Select all

<pstyle:MyStyle><cstyle:Bold>Some bold text<cstyle:>  
I'm able to get the first part right (<pstyle:MyStyle>), but cannot figure out how to save the information in the w:b-element for later use in the w:t-element. All these elements can contain lots of other elements. Sometimes there are w:b, and sometimes there are others, so I cannot "hard code" xslt.

I'm greateful for any help!

Eivind

Re: Newbie: XSLT variables?

Posted: Mon Sep 29, 2008 4:38 pm
by george
Hi Eivid,

It is hard to give you a general solution but, for your example (adding also the namespace declaration):

Code: Select all


<w:p xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
<w:pPr>
<w:pStyle w:val="MyStyle"/>
</w:pPr>
<w:r>
<w:rPr>
<w:b/>
</w:rPr>
<w:t>Some bold text</w:t>
</w:r>
</w:p>
you can get the desired output with a stylesheet like below:

Code: Select all


<?xml version="1.1" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"
version="1.0">

<xsl:output method="text"/>

<xsl:template match="w:pStyle">
<xsl:text><pstyle:</xsl:text>
<xsl:value-of select="@w:val"/>
<xsl:text>></xsl:text>
</xsl:template>


<xsl:template match="w:r/w:rPr/w:b">
<xsl:text><cstyle:Bold></xsl:text>
<xsl:apply-templates select="../following-sibling::*" mode="content"/>
<xsl:text><cstyle:></xsl:text>
</xsl:template>

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

<xsl:template match="text()"/>

</xsl:stylesheet>
Best Regards,
George

Re: Newbie: XSLT variables?

Posted: Tue Sep 30, 2008 10:34 am
by eivindan
Thank you!! That works just the way I wanted. :)