Re: [xsl] XSL pattern needed for begin/end elements

Subject: Re: [xsl] XSL pattern needed for begin/end elements
From: "Vasu Chakkera" <vasucv@xxxxxxxxxxx>
Date: Wed, 7 Jul 2004 17:45:24 +0100
Tracy,
The following are my comments regarding your source XML..
<hyperlink_begin id=3D"111" end=3D"222">
is a wrong construct...
all the attribute values must be in double quotes..
<hyperlink_begin  id="111" end="222">
is what it should be..
I dont know if this is some kind of a copy paste error or anything but 3D
seems to be appearing in all the attributes..

You have to explain
>"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."

><xsl:apply-templates select="(following-sibling::*) except
>(following-sibling::hyperlink_end[@id=3D$endID]/following-sibling::*)"/>

what did you mean when you wrote "except"?

Please go through the XSL you have pasted and please re post your question
with a XSL that makes better sence.

> I have a template that /almost/ works so feel free to let me know why it
>fails OR suggest a completely different solution
If you run the XSL you have pasted here against the XML you have pasted, I
am sure you would end up in loads of errors!!

If
<cod>
  <HyperLink xlink:href=3D"http://www.sf.net";>
    Click <b>here.</b>
  </HyperLink>
</cod>
is what you want, It can be easily done... But would want to wait till you
get back to us with a more legible XML and XSL

Cheers
Vasu
----- Original Message ----- 
From: "Tracy Atteberry" <Tracy.Atteberry@xxxxxxxxxxxx>
To: <xsl-list@xxxxxxxxxxxxxxxxxxxxxx>
Sent: Wednesday, July 07, 2004 5:14 PM
Subject: [xsl] XSL pattern needed for begin/end elements


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:

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

Target XML example:

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

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:text>://</xsl:text>
        <xsl:value-of select=3D"locator_url/@host_name"/>
    </xsl:variable>
    <xsl:variable name=3D"endID" select=3D"@end"/>
    <xsl:element name=3D"HyperLink">
        <xsl:attribute name=3D"xlink:href"><xsl:value-of
select=3D"$linkUrl"/></xsl:attribute>
        <xsl:apply-templates select=3D"(following-sibling::*) except
(following-sibling::hyperlink_end[@id=3D$endID]/following-sibling::*)"/>
    </xsl:element>
</xsl:template>

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

--+------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe@xxxxxxxxxxxxxxxxxxxxxx>
--+--


Current Thread