|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] RE: Transforming HTML to NITF
> the NITF has a <content.body> tag which is equivilant to
> HTMLs <body> tag.
> However, its children are far more rigidly defined in that it
> only allows elements as children.
>
> > I need to get the line:
> this is <em>emphasis</em> some more <b>text</b></br></br>
> > to end up wrapped in <p> tags (preferably without the <br>s)
> >
> > For clarity, the children of the body are:
> p
> ul
> | text()
> | em
> | text()
> | b
> | br
> | br
> p
>
> > I need to work with thos tags that have the | beside them
> as a single
> > block so that I can wrap the entire thing in a <p> tag.
>
An interesting positional grouping problem.
My first thought is a two-pass approach. First wrap the offending elements
individually in a <merge> tag, then do a positional grouping to merge
adgacent <merge> elements into a single <p> element.
The first stage is easy:
<xsl:template match="content.body/text() | content.body/em | ...">
<merge><xsl:copy-of select="."/></merge>
</xsl:template>
The second pass is trickier (positional grouping always is); I naturally do
it with saxon:leading(), which selects all the nodes in a node-set that
satisfy some condition, stopping at the first one that doesn't:
<xsl:template match="merge[not(preceding-sibling::*[1][self::merge])]">
<p>
<xsl:copy-of select="saxon:leading(following-sibling::*,
saxon:expression('self::merge'))"/>
</p>
</xsl:template>
The alternative is a recursive template that continues processing successive
elements until it finds one that isn't a <merge> element.
This might be a good one to add to the grouping use cases for XSLT 2.0
Mike Kay
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
|

Cart








