[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] RE: Applying templates to a mixed content node
>Using your xml and stylesheet fragment, the "tabular" element _is_ >"processed" by the xslt processor. I say that because I just tried it. >There are several questions here - > >1) Why do you say it does not when it does? The templates for <tabular> and its elements work together to output an FO table (my initial testing shows that the FO is correct and I have successfully generated standalone tables with these templates - this issue came up when I tried to integrate the table generation into my main stylesheet for formatting an entire book). The final FO file doesn't contain any <fo:table> tags in it, nor is there any evidence of the information contained in the <tabular> element or its children. I am currently using the XMLSpy debugging environment to test this transformation, so I am forced to use Altova's built-in XSLT engine (and Apache's FOP for the PDF generation). >That is partly >because you use xsl:apply-templates a second time where it will pick up >the "tabular" child element. Thus you will process both the text and >the tabular element twice, which is probably not what you want. You are right -- this is an error on my part due to experimentation. >a) What should happen if there is text but no tabular element? Should the text be emitted anyway? Yes. If there is no tabular element, the text should still be emitted. The <p><tabular> combo is the only case in the xml files where this mixed content is occurring, and the text node always comes before the <tabular> element. I appreciate all the help! Thanks, Ryan -----Original Message----- From: Passin, Tom [mailto:tpassin@xxxxxxxxxxxx] Sent: Tuesday, September 16, 2003 2:10 PM To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx Subject: RE: Applying templates to a mixed content node [Ryan Graham] > I have the following source XML (which is formed somewhat awkwardly): > > <p>Some text for the p tag. > <tabular> > <table> > ... > </table> > </tabular> > </p> > > Note that <p> contains both text and other children elements. > In processing, I would like to write the p/text() node to an > FO block, and > then continue to process the <tabular> node with templates. > These xpath > expressions seem evaluate correctly, but the processor never > processes the > <tabular> node: > Using your xml and stylesheet fragment, the "tabular" element _is_ "processed" by the xslt processor. I say that because I just tried it. There are several questions here - 1) Why do you say it does not when it does? 2) Is the way you are going about the task sensible? As to 1), do you mean that there is no output from the xslt processor, or that the result of FO processing is not what you expect? If the former, what xslt processor are you using? As to 2), it is not quite clear to me what you want to do and what your input will be, but your approach does not quite gell. That is partly because you use xsl:apply-templates a second time where it will pick up the "tabular" child element. Thus you will process both the text and the tabular element twice, which is probably not what you want. But several crucial pieces of information are missing, so that we cannot really advise you properly - a) What should happen if there is text but no tabular element? Should the text be emitted anyway? b) Can there be any text after a tabular element, and if so do you want to emit it before or after the tabular element? As an aside, it is redundant to use './' './text()' means the same thing as 'text()', for example. These are not unix path statements. > <xsl:template match="p"> > <xsl:if test="./tabular"> > <fo:block xsl:use-attribute-sets="para"> > <xsl:value-of select="./text()" /> > </fo:block> > <xsl:apply-templates select="tabular"/> > </xsl:if> > <fo:block xsl:use-attribute-sets="para"> > <xsl:apply-templates /> > </fo:block> > </xsl:template> > Ther are many possibilities for simplifying your code and getting it to do just what you want, but we need to know what you want first. Cheers, Tom P XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|