RE: [xsl] Entity Questions

Subject: RE: [xsl] Entity Questions
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Mon, 17 Jan 2005 22:14:55 -0000
> The template this starts in begins like this:
> 
> <xsl:template match="*" mode="_KCXFILE_">
> 
> NOTE:
> _KCXFILE_ contains the XML document.

No, a mode doesn't contain anything. It's a label for a template rule that
must match the mode specified when apply-templates is called: this allows
you to invoke different rules to process the same nodes under different
conditions.

 This is an existing 
> system, I didn't
> write it so am not clear on why certain things were done the 
> way they were.
> 
>  This template outputs all the FO tags to start the FO 
> document. 

It's sometimes natural to think of the transformation outputting the start
tag, then the content, then the end tag. But that's not the XSLT processing
model, and it's as well to get the right model into your head. When you see
this in the stylesheet

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

you are seeing two element nodes: a b element and an xsl:apply-templates
element. The b element is evaluated to produce a b element in the result
tree. The xsl:apply-templates element is evaluated to produce the children
of the b element in the result tree. There are two actions here, not three.
The start and end tags are produced only when the result tree is serialized;
writing an element to the result tree is an atomic operation.

You can easily spot the people who haven't understood this: they sprinkle
their stylesheets liberally with "disable-output-escaping".

> 
> While the content is being outputed there are sometimes HTML 
> tags. I want
> the system to switch those out for FO tags.

So you want to substitute template rules that output FO elements for the
existing template rules that output HTML elements.
> 
> It is within this template I would like to examine each 
> output before it is
> actually outputed for tags I would like to replace.

No, that's not the way to tackle it. Don't generate the HTML and then modify
it, replace the rules that generate HTML with rules that generate FO.

Michael Kay
http://www.saxonica.com/

Current Thread