Subject: Re: [xsl] From WordprocessingML inline styles to nested inline elements From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx> Date: Tue, 27 Mar 2007 14:16:56 -0400 |
After testing both of your solutions, I discovered that David's does not do the right thing: the inner-most run style from the hierarchy is not wrapped around the text, but ends up as a singleton element just before the run's text. Wendell's solution, however, works perfectly (after minor typo corrections), so I favour this one.
Currently, I am thinking about getting even more "static", by replacing the above generic style parsing approach by individual generated "classical" templates, each mapping one style and controlling the subsequently called templates.
So I'd start out with a template for the outermost style:
<xsl:template match="w:r[w:rPr/w:b]"> <xsl:element name="b">
Inside the template, I would like to pass the same run (w:r) to a template dealing with the next level's style, matched by "w:r[w:rPr/w:i]", and so on. I wonder how can I "materialize" the style hierarchy, read from the configuration file, into a series of properly chained templates.
My ideas: either use one mode per style-specific template, or one single named template that gets called recursively, with the current style and the run's text as parameters. Which way would you recommend?
<w:r> <w:Pr> <w:b/> <w:i> </w:Pr> <w:t>Bold, italicized text</w:t> </w:r>
<xsl:template match="w:r"> <xsl:apply-templates select="w:Pr/*[1]" mode="style"/> <xsl:if test="not(w:Pr/*)"> <!-- fail safe if we have no styles --> <xsl:value-of select="w:t"/> </xsl:if> </xsl:template>
<xsl:template match="w:Pr/*" mode="style"> <xsl:element name="local-name()"> <!-- creates an element 'b' for 'w:b', etc. --> <xsl:apply-templates select="following-sibling::*" mode="style"/> <xsl:if test="not(following-sibling::*)"> <!-- if we have no following sibling, we're done --> <xsl:value-of select="../../w:t"/> </xsl:if> </xsl:element> </xsl:template>
Cheers, Wendell
====================================================================== Wendell Piez mailto:wapiez@xxxxxxxxxxxxxxxx Mulberry Technologies, Inc. http://www.mulberrytech.com 17 West Jefferson Street Direct Phone: 301/315-9635 Suite 207 Phone: 301/315-9631 Rockville, MD 20850 Fax: 301/315-8285 ---------------------------------------------------------------------- Mulberry Technologies: A Consultancy Specializing in SGML and XML ======================================================================
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] From WordprocessingML inl, Yves Forkl | Thread | Re: [xsl] From WordprocessingML inl, Wendell Piez |
RE: [xsl] Dynamically define number, Angela Williams | Date | [xsl] Multiple String Replacements , Ignacio Garcia del C |
Month |