[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] Entity Questions


Subject: Re: [xsl] Entity Questions
From: "Luke Shannon" <lshannon@xxxxxxxxxxxxxxx>
Date: Mon, 17 Jan 2005 16:53:26 -0500

Sorry all, I am not doing a very good job of explaining this.

Let me try it from the top:

I have an XML document containing the content that I use to create my
output.

The desired output is a complete XSL:FO document.

The template this starts in begins like this:

<xsl:template match="*" mode="_KCXFILE_">

NOTE:
_KCXFILE_ contains the XML document. 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 than
begins a cascade of template calls to output the rest of the content (these
templates are spread across many files). Finally the closing tags for the FO
document are outputed and I have what I need, a complete FO document.

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

The template I pasted below is what is used in the existing system to get
specific text from the main XML document.

It is within this template I would like to examine each output before it is
actually outputed for tags I would like to replace.

David's suggestions to about placing templates throughout the page to handle
these tags is confusing to me because the entire output is create across
several pages by calling different templates. Perhaps I am not understanding
some fundemental concepts of XSL, if so please let me know (I am pretty new
to the technoloogy).

Hopefully now things may be a little more clear on what I am trying to do.

Below is the template that is output text where some tag replacement would
need to occur.

Thanks,

Luke

<!-- all text used in the FO document is outputted here -->
<xsl:template name="text_display_and_edit">
<xsl:param name="text_number" />
<xsl:param name="textname" select="concat('TEXT',$text_number)" />
<xsl:if test="DATA/VERSION/ITEM[@NAME=$textname] !=''" >
<!-- output the text from the html document where attribute name =
textname -->
<xsl:value-of select="DATA/VERSION/ITEM[@NAME=$textname]"/>
</xsl:if>
</xsl:template>

----- Original Message ----- 
From: "Michael Kay" <mike@xxxxxxxxxxxx>
To: <xsl-list@xxxxxxxxxxxxxxxxxxxxxx>
Sent: Monday, January 17, 2005 4:02 PM
Subject: RE: [xsl] Entity Questions


> The problem of handling input in which elements such as <b>, <i>, and <u>
> can be arbitrarily nested is bread-and-butter for XSLT:
>
> <xsl:template match="b">
>  <bold><xsl:apply-templates/></bold>
> </xsl:template>
>
> <xsl:template match="u">
>  <underline><xsl:apply-templates/></underline>
> </xsl:template>
>
> <xsl:template match="i">
>  <italic><xsl:apply-templates/></italic>
> </xsl:template>
>
> It's not clear from your description, but I think you might be alluding to
a
> different problem, which is multi-phase or pipeline processing: that is,
> producing a temporary tree and then doing another transformation on that.
> This works cleanly in XSLT 2.0:
>
> <xsl:variable name="temp">
>   <xsl:apply-templates select="/" mode="phase1"/>
> </xsl:variable>
>
> <xsl:template match="/">
>   <xsl:apply-templates match="$temp" mode="phase2"/>
> </xsl:template>
>
> I use two different modes here to keep the template rules for the two
phases
> of processing separate from each other. Each template rule will be
> identified as mode="phaseN" to indicate when it applies.
>
> There's a slight glitch in XSLT 1.0 which doesn't allow this syntax: to
get
> round the restriction you need to write
>
> <xsl:template match="/">
>   <xsl:apply-templates match="xx:node-set($temp)" mode="phase2"/>
> </xsl:template>
>
> where xx:node-set() is an extension function provided by your XSLT vendor.
> Every XSLT 1.0 processor provides a function of this kind, but the
namespace
> varies.
>
>
>
> >
> > I was thinking about implementing a global find and replace
> > function that
> > would take an input string, target and replacement as params. It would
> > recurse until all the targets in the string have been
> > replaced. I would have
> > to do this seperately for <p>, <i>, <b> and <font>.
>
> I'm sorry, but I can't see what this code is trying to do at all.
>
> Michael Kay
> http://www.saxonica.com/
>
>
> >
> > Is there an easier approach?
> >
> > <xsl:template name="text_display_and_edit">
> > <xsl:param name="text_number" />
> > <xsl:param name="textname" select="concat('TEXT',$text_number)" />
> > <xsl:if test="DATA/VERSION/ITEM[@NAME=$textname] !=''" >
> > <xsl:value-of select="DATA/VERSION/ITEM[@NAME=$textname]" />
> > </xsl:if>
> > </xsl:template>
> >
> > Thanks,
> >
> > Luke
> >
> > ----- Original Message ----- 
> > From: "David Carlisle" <davidc@xxxxxxxxx>
> > To: <xsl-list@xxxxxxxxxxxxxxxxxxxxxx>
> > Sent: Monday, January 17, 2005 11:29 AM
> > Subject: Re: [xsl] Entity Questions
> >
> >
> > >
> > >   But I would still like a way to replace a <p> tag with a
> > <fo:block>,
> > etc.
> > >   Can this be done at the XSL level?
> > >
> > >
> > > XSLT has no access to the tags in the document, they like
> > entities, are
> > > resolved by the XML parser before XSLT starts; but
> > replacing a p element
> > > by an fo:block one is surely the most basic XSLT operation
> > (it is quite
> > > literally) the main application for which XSLT is designed.
> > >
> > > <xsl:template match="p"><!-- or h:p if input is in a namespace -->
> > >  <fo:block>
> > >   <xsl:apply-templates/>
> > >  </fo:block>
> > > </xsl:template>
> > >
> > > David
> > >
> > >
> > ______________________________________________________________
> > __________
> > > This e-mail has been scanned for all viruses by Star. The
> > > service is powered by MessageLabs. For more information on
> > a proactive
> > > anti-virus service working around the clock, around the
> > globe, visit:
> > > http://www.star.net.uk
> > >
> > ______________________________________________________________
> > __________


Current Thread
Keywords