XSL pattern needed for begin/end elements

Subject: XSL pattern needed for begin/end elements
From: "Tracy Atteberry" <Tracy.Atteberry@xxxxxxxxxxxx>
Date: Wed, 7 Jul 2004 11:14:50 -0500
Hi all,

I'm looking for an XSL pattern to solve the problem of going from XML
that has separate begin and end elements to one that does not.

Please, please note that I do not control either the source or target
XML formats.  If I did, this would be much easier.

Source XML snip:

  <hyperlink_begin id=3D"111" end=3D"222">
    <locator_url protocol=3D"http" host_name=3D"www.sf.net"/>
  <text_run emphasis=3D"bold">here.</text_run>
  <hyperlink_end id=3D"222" begin=3D"111"/>

Target XML example:

  <HyperLink xlink:href=3D"http://www.sf.net";>
    Click <b>here.</b>

In my case I can assume that associated begin and end hyperlink tags
will occur as siblings -- though generally this is not the case and in
fact, this is the reason the begin and end tags are unique elements.

I have a template that /almost/ works so feel free to let me know why it
fails OR suggest a completely different solution.

Current XSL template snip:

<xsl:template match=3D"//hyperlink_begin">
    <xsl:variable name=3D"linkUrl">
        <xsl:value-of select=3D"locator_url/@protocol"/>
        <xsl:value-of select=3D"locator_url/@host_name"/>
    <xsl:variable name=3D"endID" select=3D"@end"/>
    <xsl:element name=3D"HyperLink">
        <xsl:attribute name=3D"xlink:href"><xsl:value-of
        <xsl:apply-templates select=3D"(following-sibling::*) except

This produces the correct hyperlink but the template for text_run
elements gets called twice this way -- once inside the hyperlink, then
again as templates continue to be applied.

Any help would be greatly appreciated.  Thanks!

Tracy Atteberry

PS. I'm using Saxon 8

Current Thread