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

Re: [xsl] Recursively link XML blocks


Subject: Re: [xsl] Recursively link XML blocks
From: "Mitch C. Amiano" <Mitch.Amiano@xxxxxxxxxxx>
Date: Mon, 26 Nov 2001 11:16:39 -0500

Will this do?

I took the liberty of creating a sample WF doc from your fragment:

<?xml version="1.0"?>
<recursivecompose>
...
<element_A>
     textA textA textA
     <insert>element_B</insert>
     textA textA textA
</element_A>

<element_B>
     textB textB textB
     <insert>element_C</insert>
     textB textB textB
</element_B>

<element_C>
     textC textC textC
     textC textC textC
</element_C>
....etc.
</recursivecompose>

Then, assuming I *don't* know exactly what the element structure may be,
You may be able to use following:: or another XPath to improve upon the
//*, if you
can make a guarantee about the element structure.

The first apply-templates processes "element_A" explicitly. You could
alternatively
test for an attribute value, or for the first element child - whatever
you know 
that points to the root of your compositional heirarchy. 

Note that this puts a steep price on the user, should they fail to avoid
a loop 
in the linking. If, for instance, you <insert> element_C into itself,
the XSLT
engine may keep recursing until it dies. (Saxon 6.4.3 did.)

<?xml version="1.0" ?>
<xsl:stylesheet 
   xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
   version="1.0"
>
<xsl:output method="text"/>

<xsl:template match="/*">
   <xsl:apply-templates select="element_A" />
</xsl:template>

<xsl:template match="insert">
   <xsl:apply-templates select="//*[local-name() = current()]"/>
</xsl:template>

</xsl:stylesheet>

Costantino_Sertorio@xxxxxxxxxx wrote:
> 
> Hello everybody,
> I am trying (without success, at the moment...) to do the following:
> 
> XML document:
> ...
> <element_A>
>      textA textA textA
>      <insert>element_B</insert>
>      textA textA textA
> </element_A>
> 
> <element_B>
>      textB textB textB
>      <insert>element_C</insert>
>      textB textB textB
> </element_B>
> 
> <element_C>
>      textC textC textC
>      textC textC textC
> </element_C>
> ....etc.
> 
> Desired output:
>      textA textA textA
>      textB textB textB
>      textC textC textC
>      textC textC textC
>      textB textB textB
>      textA textA textA
> 
> In other words, I would like to "link" elements to other elements, and compose a
> new document "recursively".
> This is exactly the same behaviour that I may obtain by changing my "content
> architecture", and putting all the text directly in the XSL, and then using
> "xsl:call-template"s to include one block in another.
> But if I do that I have to mix pure text with layout definitions (I want to
> output HTML and FO from the XML) - and therefore I will have to maintain two
> sets of documents.
> Does anybody have a suggestion?
> Thank you very much,
> 
> Costantino
> 
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list

--
Mitch.Amiano (@...)
SW Development Engineer in C++/Java/Perl/TCL/SQL/XML/XSLT/XPath
Advance Design Process Group, Raleigh Engineering Services     Alcatel
USA

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list



Current Thread
Keywords