dwergkees wrote:
>> Why don't you simply do
>> <xsl:template match="w:r"><xsl:apply-templates /></xsl:template>
>>
>> <xsl:template match="w:i">
>> <i><xsl:apply-templates /></i>
>> </xsl:template>
>>
>> <xsl:template match="w:b">
>> <b><xsl:apply-templates /></b>
>> </xsl:template>
>
>
> I've tried fussin' about with your solution, but i can't get it to fit
> just right. I'll show a small WordML example to demonstrate the problem
> more clearly:
>
> WordML:
>
> <w
>
> <w:r>
> <w:t>Plain text</w:t>
> </w:r>
> <w:r>
> <w:rPr>
> <w:b/>
> </w:rPr>
> <w:t>Bold text</w:t>
> </w:r>
> <w:r>
> <w:t> </w:t>
> </w:r>
> <w:r>
> <w:rPr>
> <w:i/>
> </w:rPr>
> <w:t>Italic text</w:t>
> </w:r>
> <w:r>
> <w:rPr>
> <w:b/>
> <w:i/>
> </w:rPr>
> <w:t>Bold and italic</w:t>
> </w:r>
> </w
>
This is an interesting relic of (a) the fact that Word uses out-of-line
markup and (b) the sedulous avoidance of Mixed Content common to those
who think pointers are more fun to program than trees. It's also about
the only way you can model the behaviour of unschooled authors in Word.
Just add another condition to your original:
<xsl:template match="w:r">
<xsl:choose>
<xsl:when test=".//w:i and .//w:b">
<i><b><xsl:apply-templates/></b></i>
</xsl:when>
<xsl:when test=".//w:i and not(.//w:b)">
<i><xsl:apply-templates/></i>
</xsl:when>
<xsl:when test=".//w:b and not(.//w:i)">
<b><xsl:apply-templates/></b>
</xsl:when>
<xsl

therwise>
<xsl:apply-templates/>
</xsl

therwise>
</xsl:choose>
</xsl:template>
> Should transform to:
>
> <p>Plain text <b>Bold text</b> <i>Italic text</i> <i><b>Bold and
> italic</b></i></p>
No, there is no white-space after "Plain text" nor after "Italic text"
in your quoted XML document. If you need to introduce extra white-space
you need to specify the rules for doing so.
> As you can see, the <w:i/> and <w:b/> tags are grandchildren of the r
> element, the text itself is a child of the r element. So at each r
> element I want to check the existence of w:i and w:b and surround the t
> element with the corresponding HTML. Your solution matches the
> existence, but then the processor is at the wrong current Node. (As far
> as I understand the complexities of xslt).
>
> Any thoughts?
Here's another way to do it, based on Martin's suggestion of using the
normal "apply-templates" way of proceeding down a document. You'll have
to jiggle the declared namespace for w: as I don't know what your
document declares it as. This method will handle anything occurring in
w:rPr, not just bold and italics.
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0"
xmlns:w="http://foo.bar.org"
xmlns

sl="http://www.w3.org/1999/XSL/Transform">
<xsl

utput method="html"/>
<xsl:strip-space elements="*"/>
<xsl

reserve-space elements="w:t"/>
<xsl:template match="w

">
<p>
<xsl:apply-templates/>
</p>
</xsl:template>
<xsl:template match="w:r">
<xsl:choose>
<xsl:when test="w:rPr">
<xsl:call-template name="nest">
<xsl:with-param name="styles" select="w:rPr/*"/>
</xsl:call-template>
</xsl:when>
<xsl

therwise>
<xsl:apply-templates/>
</xsl

therwise>
</xsl:choose>
</xsl:template>
<xsl:template name="nest">
<xsl

aram name="styles"/>
<xsl

aram name="counter">
<xsl:text>1</xsl:text>
</xsl

aram>
<xsl:choose>
<xsl:when test="$counter>count($styles)">
<xsl:value-of select="w:t"/>
</xsl:when>
<xsl

therwise>
<xsl:element name="{local-name($styles[$counter])}">
<xsl:call-template name="nest">
<xsl:with-param name="styles" select="$styles"/>
<xsl:with-param name="counter" select="$counter+1"/>
</xsl:call-template>
</xsl:element>
</xsl

therwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
In this, I am stripping all space except in w:t. This will preserve the
otherwise vulnerable white-space-only node.
///Peter
--
XML FAQ:
http://xml.silmaril.ie/